MediaWiki  1.30.0
ReplicatedBagOStuff.php
Go to the documentation of this file.
1 <?php
35  protected $writeStore;
37  protected $readStore;
38 
49  public function __construct( $params ) {
50  parent::__construct( $params );
51 
52  if ( !isset( $params['writeFactory'] ) ) {
53  throw new InvalidArgumentException(
54  __METHOD__ . ': the "writeFactory" parameter is required' );
55  }
56  if ( !isset( $params['readFactory'] ) ) {
57  throw new InvalidArgumentException(
58  __METHOD__ . ': the "readFactory" parameter is required' );
59  }
60 
61  $opts = [ 'reportDupes' => false ]; // redundant
62  $this->writeStore = ( $params['writeFactory'] instanceof BagOStuff )
63  ? $params['writeFactory']
64  : ObjectFactory::getObjectFromSpec( $opts + $params['writeFactory'] );
65  $this->readStore = ( $params['readFactory'] instanceof BagOStuff )
66  ? $params['readFactory']
67  : ObjectFactory::getObjectFromSpec( $opts + $params['readFactory'] );
68  $this->attrMap = $this->mergeFlagMaps( [ $this->readStore, $this->writeStore ] );
69  }
70 
71  public function setDebug( $debug ) {
72  $this->writeStore->setDebug( $debug );
73  $this->readStore->setDebug( $debug );
74  }
75 
76  protected function doGet( $key, $flags = 0 ) {
77  return ( $flags & self::READ_LATEST )
78  ? $this->writeStore->get( $key, $flags )
79  : $this->readStore->get( $key, $flags );
80  }
81 
82  public function getMulti( array $keys, $flags = 0 ) {
83  return ( $flags & self::READ_LATEST )
84  ? $this->writeStore->getMulti( $keys, $flags )
85  : $this->readStore->getMulti( $keys, $flags );
86  }
87 
88  public function set( $key, $value, $exptime = 0, $flags = 0 ) {
89  return $this->writeStore->set( $key, $value, $exptime, $flags );
90  }
91 
92  public function delete( $key ) {
93  return $this->writeStore->delete( $key );
94  }
95 
96  public function add( $key, $value, $exptime = 0 ) {
97  return $this->writeStore->add( $key, $value, $exptime );
98  }
99 
100  public function incr( $key, $value = 1 ) {
101  return $this->writeStore->incr( $key, $value );
102  }
103 
104  public function decr( $key, $value = 1 ) {
105  return $this->writeStore->decr( $key, $value );
106  }
107 
108  public function lock( $key, $timeout = 6, $expiry = 6, $rclass = '' ) {
109  return $this->writeStore->lock( $key, $timeout, $expiry, $rclass );
110  }
111 
112  public function unlock( $key ) {
113  return $this->writeStore->unlock( $key );
114  }
115 
116  public function merge( $key, callable $callback, $exptime = 0, $attempts = 10, $flags = 0 ) {
117  return $this->writeStore->merge( $key, $callback, $exptime, $attempts, $flags );
118  }
119 
120  public function getLastError() {
121  return ( $this->writeStore->getLastError() != self::ERR_NONE )
122  ? $this->writeStore->getLastError()
123  : $this->readStore->getLastError();
124  }
125 
126  public function clearLastError() {
127  $this->writeStore->clearLastError();
128  $this->readStore->clearLastError();
129  }
130 }
false
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:187
ReplicatedBagOStuff\$readStore
BagOStuff $readStore
Definition: ReplicatedBagOStuff.php:37
ReplicatedBagOStuff\getLastError
getLastError()
Get the "last error" registered; clearLastError() should be called manually.
Definition: ReplicatedBagOStuff.php:120
ReplicatedBagOStuff\incr
incr( $key, $value=1)
Increase stored value of $key by $value while preserving its TTL.
Definition: ReplicatedBagOStuff.php:100
ReplicatedBagOStuff\$writeStore
BagOStuff $writeStore
Definition: ReplicatedBagOStuff.php:35
$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:47
ReplicatedBagOStuff\lock
lock( $key, $timeout=6, $expiry=6, $rclass='')
Acquire an advisory lock on a key string.
Definition: ReplicatedBagOStuff.php:108
BagOStuff\ERR_NONE
const ERR_NONE
Possible values for getLastError()
Definition: BagOStuff.php:77
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
$debug
$debug
Definition: mcc.php:31
ReplicatedBagOStuff\add
add( $key, $value, $exptime=0)
Definition: ReplicatedBagOStuff.php:96
ReplicatedBagOStuff\clearLastError
clearLastError()
Clear the "last error" registry.
Definition: ReplicatedBagOStuff.php:126
BagOStuff\mergeFlagMaps
mergeFlagMaps(array $bags)
Merge the flag maps of one or more BagOStuff objects into a "lowest common denominator" map.
Definition: BagOStuff.php:783
$value
$value
Definition: styleTest.css.php:45
ObjectFactory\getObjectFromSpec
static getObjectFromSpec( $spec)
Instantiate an object based on a specification array.
Definition: ObjectFactory.php:58
ReplicatedBagOStuff\setDebug
setDebug( $debug)
Definition: ReplicatedBagOStuff.php:71
ReplicatedBagOStuff\__construct
__construct( $params)
Constructor.
Definition: ReplicatedBagOStuff.php:49
ReplicatedBagOStuff
A cache class that directs writes to one set of servers and reads to another.
Definition: ReplicatedBagOStuff.php:33
$keys
$keys
Definition: testCompression.php:65
ReplicatedBagOStuff\merge
merge( $key, callable $callback, $exptime=0, $attempts=10, $flags=0)
Merge changes into the existing cache value (possibly creating a new one)
Definition: ReplicatedBagOStuff.php:116
ReplicatedBagOStuff\unlock
unlock( $key)
Release an advisory lock on a key string.
Definition: ReplicatedBagOStuff.php:112
ReplicatedBagOStuff\doGet
doGet( $key, $flags=0)
Definition: ReplicatedBagOStuff.php:76
ReplicatedBagOStuff\getMulti
getMulti(array $keys, $flags=0)
Get an associative array containing the item for each of the keys that have items.
Definition: ReplicatedBagOStuff.php:82
ReplicatedBagOStuff\decr
decr( $key, $value=1)
Decrease stored value of $key by $value while preserving its TTL.
Definition: ReplicatedBagOStuff.php:104
$flags
it s the revision text itself In either if gzip is the revision text is gzipped $flags
Definition: hooks.txt:2801
array
the array() calling protocol came about after MediaWiki 1.4rc1.