MediaWiki  1.33.0
ReplicatedBagOStuff.php
Go to the documentation of this file.
1 <?php
21 use Wikimedia\ObjectFactory;
22 
36  protected $writeStore;
38  protected $readStore;
39 
50  public function __construct( $params ) {
51  parent::__construct( $params );
52 
53  if ( !isset( $params['writeFactory'] ) ) {
54  throw new InvalidArgumentException(
55  __METHOD__ . ': the "writeFactory" parameter is required' );
56  }
57  if ( !isset( $params['readFactory'] ) ) {
58  throw new InvalidArgumentException(
59  __METHOD__ . ': the "readFactory" parameter is required' );
60  }
61 
62  $opts = [ 'reportDupes' => false ]; // redundant
63  $this->writeStore = ( $params['writeFactory'] instanceof BagOStuff )
64  ? $params['writeFactory']
65  : ObjectFactory::getObjectFromSpec( $opts + $params['writeFactory'] );
66  $this->readStore = ( $params['readFactory'] instanceof BagOStuff )
67  ? $params['readFactory']
68  : ObjectFactory::getObjectFromSpec( $opts + $params['readFactory'] );
69  $this->attrMap = $this->mergeFlagMaps( [ $this->readStore, $this->writeStore ] );
70  }
71 
72  public function setDebug( $debug ) {
73  $this->writeStore->setDebug( $debug );
74  $this->readStore->setDebug( $debug );
75  }
76 
77  public function get( $key, $flags = 0 ) {
78  return ( $flags & self::READ_LATEST )
79  ? $this->writeStore->get( $key, $flags )
80  : $this->readStore->get( $key, $flags );
81  }
82 
83  public function set( $key, $value, $exptime = 0, $flags = 0 ) {
84  return $this->writeStore->set( $key, $value, $exptime, $flags );
85  }
86 
87  public function delete( $key, $flags = 0 ) {
88  return $this->writeStore->delete( $key, $flags );
89  }
90 
91  public function add( $key, $value, $exptime = 0, $flags = 0 ) {
92  return $this->writeStore->add( $key, $value, $exptime, $flags );
93  }
94 
95  public function merge( $key, callable $callback, $exptime = 0, $attempts = 10, $flags = 0 ) {
96  return $this->writeStore->merge( $key, $callback, $exptime, $attempts, $flags );
97  }
98 
99  public function changeTTL( $key, $exptime = 0, $flags = 0 ) {
100  return $this->writeStore->changeTTL( $key, $exptime, $flags );
101  }
102 
103  public function lock( $key, $timeout = 6, $expiry = 6, $rclass = '' ) {
104  return $this->writeStore->lock( $key, $timeout, $expiry, $rclass );
105  }
106 
107  public function unlock( $key ) {
108  return $this->writeStore->unlock( $key );
109  }
110 
111  public function deleteObjectsExpiringBefore( $date, $progressCallback = false ) {
112  return $this->writeStore->deleteObjectsExpiringBefore( $date, $progressCallback );
113  }
114 
115  public function getMulti( array $keys, $flags = 0 ) {
116  return ( ( $flags & self::READ_LATEST ) == self::READ_LATEST )
117  ? $this->writeStore->getMulti( $keys, $flags )
118  : $this->readStore->getMulti( $keys, $flags );
119  }
120 
121  public function setMulti( array $data, $exptime = 0, $flags = 0 ) {
122  return $this->writeStore->setMulti( $data, $exptime, $flags );
123  }
124 
125  public function deleteMulti( array $keys, $flags = 0 ) {
126  return $this->writeStore->deleteMulti( $keys, $flags );
127  }
128 
129  public function incr( $key, $value = 1 ) {
130  return $this->writeStore->incr( $key, $value );
131  }
132 
133  public function decr( $key, $value = 1 ) {
134  return $this->writeStore->decr( $key, $value );
135  }
136 
137  public function incrWithInit( $key, $ttl, $value = 1, $init = 1 ) {
138  return $this->writeStore->incrWithInit( $key, $ttl, $value, $init );
139  }
140 
141  public function getLastError() {
142  return ( $this->writeStore->getLastError() != self::ERR_NONE )
143  ? $this->writeStore->getLastError()
144  : $this->readStore->getLastError();
145  }
146 
147  public function clearLastError() {
148  $this->writeStore->clearLastError();
149  $this->readStore->clearLastError();
150  }
151 
152  public function makeKeyInternal( $keyspace, $args ) {
153  return $this->writeStore->makeKeyInternal( ...func_get_args() );
154  }
155 
156  public function makeKey( $class, $component = null ) {
157  return $this->writeStore->makeKey( ...func_get_args() );
158  }
159 
160  public function makeGlobalKey( $class, $component = null ) {
161  return $this->writeStore->makeGlobalKey( ...func_get_args() );
162  }
163 
164  protected function doGet( $key, $flags = 0, &$casToken = null ) {
165  throw new LogicException( __METHOD__ . ': proxy class does not need this method.' );
166  }
167 }
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:38
ReplicatedBagOStuff\setMulti
setMulti(array $data, $exptime=0, $flags=0)
Batch insertion/replace.
Definition: ReplicatedBagOStuff.php:121
ReplicatedBagOStuff\getLastError
getLastError()
Get the "last error" registered; clearLastError() should be called manually.
Definition: ReplicatedBagOStuff.php:141
ReplicatedBagOStuff\makeKeyInternal
makeKeyInternal( $keyspace, $args)
Construct a cache key.
Definition: ReplicatedBagOStuff.php:152
IExpiringStore\ERR_NONE
const ERR_NONE
Definition: IExpiringStore.php:63
ReplicatedBagOStuff\incr
incr( $key, $value=1)
Increase stored value of $key by $value while preserving its TTL.
Definition: ReplicatedBagOStuff.php:129
ReplicatedBagOStuff\deleteObjectsExpiringBefore
deleteObjectsExpiringBefore( $date, $progressCallback=false)
Delete all objects expiring before a certain date.
Definition: ReplicatedBagOStuff.php:111
ReplicatedBagOStuff\$writeStore
BagOStuff $writeStore
Definition: ReplicatedBagOStuff.php:36
$params
$params
Definition: styleTest.css.php:44
BagOStuff
Class representing a cache/ephemeral data store.
Definition: BagOStuff.php:58
ReplicatedBagOStuff\lock
lock( $key, $timeout=6, $expiry=6, $rclass='')
Acquire an advisory lock on a key string.
Definition: ReplicatedBagOStuff.php:103
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\incrWithInit
incrWithInit( $key, $ttl, $value=1, $init=1)
Increase stored value of $key by $value while preserving its TTL.
Definition: ReplicatedBagOStuff.php:137
$data
$data
Utility to generate mapping file used in mw.Title (phpCharToUpper.json)
Definition: generatePhpCharToUpperMappings.php:13
ReplicatedBagOStuff\doGet
doGet( $key, $flags=0, &$casToken=null)
Definition: ReplicatedBagOStuff.php:164
ReplicatedBagOStuff\clearLastError
clearLastError()
Clear the "last error" registry.
Definition: ReplicatedBagOStuff.php:147
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
array
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
ReplicatedBagOStuff\makeGlobalKey
makeGlobalKey( $class, $component=null)
Make a global cache key.
Definition: ReplicatedBagOStuff.php:160
BagOStuff\mergeFlagMaps
mergeFlagMaps(array $bags)
Merge the flag maps of one or more BagOStuff objects into a "lowest common denominator" map.
Definition: BagOStuff.php:793
$value
$value
Definition: styleTest.css.php:49
ReplicatedBagOStuff\setDebug
setDebug( $debug)
Definition: ReplicatedBagOStuff.php:72
ReplicatedBagOStuff\__construct
__construct( $params)
Constructor.
Definition: ReplicatedBagOStuff.php:50
$args
if( $line===false) $args
Definition: cdb.php:64
ReplicatedBagOStuff\makeKey
makeKey( $class, $component=null)
Make a cache key, scoped to this instance's keyspace.
Definition: ReplicatedBagOStuff.php:156
ReplicatedBagOStuff
A cache class that directs writes to one set of servers and reads to another.
Definition: ReplicatedBagOStuff.php:34
$keys
$keys
Definition: testCompression.php:67
ReplicatedBagOStuff\add
add( $key, $value, $exptime=0, $flags=0)
Insert an item if it does not already exist.
Definition: ReplicatedBagOStuff.php:91
BagOStuff\$keyspace
string $keyspace
Definition: BagOStuff.php:64
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:95
ReplicatedBagOStuff\unlock
unlock( $key)
Release an advisory lock on a key string.
Definition: ReplicatedBagOStuff.php:107
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:115
ReplicatedBagOStuff\decr
decr( $key, $value=1)
Decrease stored value of $key by $value while preserving its TTL.
Definition: ReplicatedBagOStuff.php:133
ReplicatedBagOStuff\deleteMulti
deleteMulti(array $keys, $flags=0)
Batch deletion.
Definition: ReplicatedBagOStuff.php:125
ReplicatedBagOStuff\changeTTL
changeTTL( $key, $exptime=0, $flags=0)
Change the expiration on a key if it exists.
Definition: ReplicatedBagOStuff.php:99