Localisation updates from https://translatewiki.net.
[mediawiki.git] / includes / objectcache / ReplicatedBagOStuff.php
blob7aa2cc3d76080dc7e9420e80379c86f257417a06
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
18 * @file
19 * @ingroup Cache
20 * @author Aaron Schulz
23 /**
24 * A cache class that directs writes to one set of servers and reads to
25 * another. This assumes that the servers used for reads are setup to slave
26 * those that writes go to. This can easily be used with redis for example.
28 * In the WAN scenario (e.g. multi-datacenter case), this is useful when
29 * writes are rare or usually takes place on the primary datacenter.
31 * @ingroup Cache
32 * @since 1.25
34 class ReplicatedBagOStuff extends BagOStuff {
35 /** @var BagOStuff */
36 protected $mCache;
37 /** @var BagOStuff */
38 protected $sCache;
40 /**
41 * Constructor. Parameters are:
42 * - masterCache : Cache parameter structures, in the style required by $wgObjectCaches.
43 * See the documentation of $wgObjectCaches for more detail.
44 * - slaveCache : Cache parameter structures, in the style required by $wgObjectCaches.
45 * See the documentation of $wgObjectCaches for more detail.
47 * @param array $params
48 * @throws MWException
50 public function __construct( $params ) {
51 parent::__construct( $params );
53 if ( !isset( $params['masterCache'] ) ) {
54 throw new MWException( __METHOD__ . ': the "masterCache" parameter is required' );
55 } elseif ( !isset( $params['slaveCache'] ) ) {
56 throw new MWException( __METHOD__ . ': the "slaveCache" parameter is required' );
59 $this->mCache = ( $params['masterCache'] instanceof BagOStuff )
60 ? $params['masterCache']
61 : ObjectCache::newFromParams( $params['masterCache'] );
62 $this->sCache = ( $params['slaveCache'] instanceof BagOStuff )
63 ? $params['slaveCache']
64 : ObjectCache::newFromParams( $params['slaveCache'] );
67 public function setDebug( $debug ) {
68 $this->mCache->setDebug( $debug );
69 $this->sCache->setDebug( $debug );
72 public function get( $key, &$casToken = null ) {
73 return $this->sCache->get( $key, $casToken );
76 public function getMulti( $keys ) {
77 return $this->sCache->getMulti( $keys );
80 public function set( $key, $value, $exptime = 0 ) {
81 return $this->mCache->set( $key, $value, $exptime );
84 public function delete( $key ) {
85 return $this->mCache->delete( $key );
88 public function add( $key, $value, $exptime = 0 ) {
89 return $this->mCache->add( $key, $value, $exptime );
92 public function incr( $key, $value = 1 ) {
93 return $this->mCache->incr( $key, $value );
96 public function decr( $key ) {
97 return $this->mCache->decr( $key );
100 public function lock( $key, $timeout = 6, $expiry = 6 ) {
101 return $this->mCache->lock( $key, $timeout, $expiry );
104 public function unlock( $key ) {
105 return $this->mCache->unlock( $key );
108 public function merge( $key, $callback, $exptime = 0, $attempts = 10 ) {
109 return $this->mCache->merge( $key, $callback, $exptime, $attempts );
112 public function getLastError() {
113 return ( $this->mCache->getLastError() != self::ERR_NONE )
114 ? $this->mCache->getLastError()
115 : $this->sCache->getLastError();
118 public function clearLastError() {
119 $this->mCache->clearLastError();
120 $this->sCache->clearLastError();