MediaWiki  1.23.2
MultiWriteBagOStuff.php
Go to the documentation of this file.
1 <?php
32  var $caches;
33 
44  public function __construct( $params ) {
45  if ( !isset( $params['caches'] ) ) {
46  throw new MWException( __METHOD__ . ': the caches parameter is required' );
47  }
48 
49  $this->caches = array();
50  foreach ( $params['caches'] as $cacheInfo ) {
51  $this->caches[] = ObjectCache::newFromParams( $cacheInfo );
52  }
53  }
54 
58  public function setDebug( $debug ) {
59  $this->doWrite( 'setDebug', $debug );
60  }
61 
67  public function get( $key, &$casToken = null ) {
68  foreach ( $this->caches as $cache ) {
69  $value = $cache->get( $key );
70  if ( $value !== false ) {
71  return $value;
72  }
73  }
74  return false;
75  }
76 
84  public function cas( $casToken, $key, $value, $exptime = 0 ) {
85  throw new MWException( "CAS is not implemented in " . __CLASS__ );
86  }
87 
94  public function set( $key, $value, $exptime = 0 ) {
95  return $this->doWrite( 'set', $key, $value, $exptime );
96  }
97 
103  public function delete( $key, $time = 0 ) {
104  return $this->doWrite( 'delete', $key, $time );
105  }
106 
113  public function add( $key, $value, $exptime = 0 ) {
114  return $this->doWrite( 'add', $key, $value, $exptime );
115  }
116 
123  public function replace( $key, $value, $exptime = 0 ) {
124  return $this->doWrite( 'replace', $key, $value, $exptime );
125  }
126 
132  public function incr( $key, $value = 1 ) {
133  return $this->doWrite( 'incr', $key, $value );
134  }
135 
141  public function decr( $key, $value = 1 ) {
142  return $this->doWrite( 'decr', $key, $value );
143  }
144 
150  public function lock( $key, $timeout = 0 ) {
151  // Lock only the first cache, to avoid deadlocks
152  if ( isset( $this->caches[0] ) ) {
153  return $this->caches[0]->lock( $key, $timeout );
154  } else {
155  return true;
156  }
157  }
158 
163  public function unlock( $key ) {
164  if ( isset( $this->caches[0] ) ) {
165  return $this->caches[0]->unlock( $key );
166  } else {
167  return true;
168  }
169  }
170 
178  public function merge( $key, closure $callback, $exptime = 0, $attempts = 10 ) {
179  return $this->doWrite( 'merge', $key, $callback, $exptime );
180  }
181 
182  public function getLastError() {
183  return isset( $this->caches[0] ) ? $this->caches[0]->getLastError() : self::ERR_NONE;
184  }
185 
186  public function clearLastError() {
187  if ( isset( $this->caches[0] ) ) {
188  $this->caches[0]->clearLastError();
189  }
190  }
191 
196  protected function doWrite( $method /*, ... */ ) {
197  $ret = true;
198  $args = func_get_args();
199  array_shift( $args );
200 
201  foreach ( $this->caches as $cache ) {
202  if ( !call_user_func_array( array( $cache, $method ), $args ) ) {
203  $ret = false;
204  }
205  }
206  return $ret;
207  }
208 
217  public function deleteObjectsExpiringBefore( $date, $progressCallback = false ) {
218  $ret = false;
219  foreach ( $this->caches as $cache ) {
220  if ( $cache->deleteObjectsExpiringBefore( $date, $progressCallback ) ) {
221  $ret = true;
222  }
223  }
224  return $ret;
225  }
226 }
$time
see documentation in includes Linker php for Linker::makeImageLink & $time
Definition: hooks.txt:1358
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
MultiWriteBagOStuff\cas
cas( $casToken, $key, $value, $exptime=0)
Definition: MultiWriteBagOStuff.php:84
MultiWriteBagOStuff\getLastError
getLastError()
Get the "last error" registered; clearLastError() should be called manually.
Definition: MultiWriteBagOStuff.php:182
MultiWriteBagOStuff\setDebug
setDebug( $debug)
Definition: MultiWriteBagOStuff.php:58
$ret
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses & $ret
Definition: hooks.txt:1530
MultiWriteBagOStuff\clearLastError
clearLastError()
Clear the "last error" registry.
Definition: MultiWriteBagOStuff.php:186
$params
$params
Definition: styleTest.css.php:40
BagOStuff
interface is intended to be more or less compatible with the PHP memcached client.
Definition: BagOStuff.php:43
BagOStuff\ERR_NONE
const ERR_NONE
Possible values for getLastError()
Definition: BagOStuff.php:49
MultiWriteBagOStuff\$caches
$caches
Definition: MultiWriteBagOStuff.php:32
MultiWriteBagOStuff\incr
incr( $key, $value=1)
Definition: MultiWriteBagOStuff.php:132
MWException
MediaWiki exception.
Definition: MWException.php:26
MultiWriteBagOStuff\unlock
unlock( $key)
Definition: MultiWriteBagOStuff.php:163
MultiWriteBagOStuff\add
add( $key, $value, $exptime=0)
Definition: MultiWriteBagOStuff.php:113
MultiWriteBagOStuff\lock
lock( $key, $timeout=0)
Definition: MultiWriteBagOStuff.php:150
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
MultiWriteBagOStuff\deleteObjectsExpiringBefore
deleteObjectsExpiringBefore( $date, $progressCallback=false)
Delete objects expiring before a certain date.
Definition: MultiWriteBagOStuff.php:217
MultiWriteBagOStuff\decr
decr( $key, $value=1)
Definition: MultiWriteBagOStuff.php:141
MultiWriteBagOStuff\__construct
__construct( $params)
Constructor.
Definition: MultiWriteBagOStuff.php:44
$value
$value
Definition: styleTest.css.php:45
MultiWriteBagOStuff
A cache class that replicates all writes to multiple child caches.
Definition: MultiWriteBagOStuff.php:31
MultiWriteBagOStuff\merge
merge( $key, closure $callback, $exptime=0, $attempts=10)
Definition: MultiWriteBagOStuff.php:178
$args
if( $line===false) $args
Definition: cdb.php:62
$debug
$debug
Definition: Setup.php:498
$cache
$cache
Definition: mcc.php:32
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
MultiWriteBagOStuff\doWrite
doWrite( $method)
Definition: MultiWriteBagOStuff.php:196
ObjectCache\newFromParams
static newFromParams( $params)
Create a new cache object from parameters.
Definition: ObjectCache.php:83
MultiWriteBagOStuff\replace
replace( $key, $value, $exptime=0)
Definition: MultiWriteBagOStuff.php:123