MediaWiki  master
ReplicatedBagOStuff.php
Go to the documentation of this file.
1 <?php
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( $enabled ) {
73  parent::setDebug( $enabled );
74  $this->writeStore->setDebug( $enabled );
75  $this->readStore->setDebug( $enabled );
76  }
77 
78  public function get( $key, $flags = 0 ) {
79  return ( ( $flags & self::READ_LATEST ) == self::READ_LATEST )
80  ? $this->writeStore->get( $key, $flags )
81  : $this->readStore->get( $key, $flags );
82  }
83 
84  public function set( $key, $value, $exptime = 0, $flags = 0 ) {
85  return $this->writeStore->set( $key, $value, $exptime, $flags );
86  }
87 
88  public function delete( $key, $flags = 0 ) {
89  return $this->writeStore->delete( $key, $flags );
90  }
91 
92  public function add( $key, $value, $exptime = 0, $flags = 0 ) {
93  return $this->writeStore->add( $key, $value, $exptime, $flags );
94  }
95 
96  public function merge( $key, callable $callback, $exptime = 0, $attempts = 10, $flags = 0 ) {
97  return $this->writeStore->merge( $key, $callback, $exptime, $attempts, $flags );
98  }
99 
100  public function changeTTL( $key, $exptime = 0, $flags = 0 ) {
101  return $this->writeStore->changeTTL( $key, $exptime, $flags );
102  }
103 
104  public function lock( $key, $timeout = 6, $expiry = 6, $rclass = '' ) {
105  return $this->writeStore->lock( $key, $timeout, $expiry, $rclass );
106  }
107 
108  public function unlock( $key ) {
109  return $this->writeStore->unlock( $key );
110  }
111 
113  $timestamp,
114  callable $progress = null,
115  $limit = INF
116  ) {
117  return $this->writeStore->deleteObjectsExpiringBefore( $timestamp, $progress, $limit );
118  }
119 
120  public function getMulti( array $keys, $flags = 0 ) {
121  return ( ( $flags & self::READ_LATEST ) == self::READ_LATEST )
122  ? $this->writeStore->getMulti( $keys, $flags )
123  : $this->readStore->getMulti( $keys, $flags );
124  }
125 
126  public function setMulti( array $data, $exptime = 0, $flags = 0 ) {
127  return $this->writeStore->setMulti( $data, $exptime, $flags );
128  }
129 
130  public function deleteMulti( array $keys, $flags = 0 ) {
131  return $this->writeStore->deleteMulti( $keys, $flags );
132  }
133 
134  public function changeTTLMulti( array $keys, $exptime, $flags = 0 ) {
135  return $this->writeStore->changeTTLMulti( $keys, $exptime, $flags );
136  }
137 
138  public function incr( $key, $value = 1 ) {
139  return $this->writeStore->incr( $key, $value );
140  }
141 
142  public function decr( $key, $value = 1 ) {
143  return $this->writeStore->decr( $key, $value );
144  }
145 
146  public function incrWithInit( $key, $ttl, $value = 1, $init = 1 ) {
147  return $this->writeStore->incrWithInit( $key, $ttl, $value, $init );
148  }
149 
150  public function getLastError() {
151  return ( $this->writeStore->getLastError() != self::ERR_NONE )
152  ? $this->writeStore->getLastError()
153  : $this->readStore->getLastError();
154  }
155 
156  public function clearLastError() {
157  $this->writeStore->clearLastError();
158  $this->readStore->clearLastError();
159  }
160 
161  public function makeKeyInternal( $keyspace, $args ) {
162  return $this->writeStore->makeKeyInternal( ...func_get_args() );
163  }
164 
165  public function makeKey( $class, ...$components ) {
166  return $this->writeStore->makeKey( ...func_get_args() );
167  }
168 
169  public function makeGlobalKey( $class, ...$components ) {
170  return $this->writeStore->makeGlobalKey( ...func_get_args() );
171  }
172 
173  public function addBusyCallback( callable $workCallback ) {
174  $this->writeStore->addBusyCallback( $workCallback );
175  }
176 
177  public function setMockTime( &$time ) {
178  parent::setMockTime( $time );
179  $this->writeStore->setMockTime( $time );
180  $this->readStore->setMockTime( $time );
181  }
182 }
makeGlobalKey( $class,... $components)
Make a global cache key.
__construct( $params)
Constructor.
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:193
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
add( $key, $value, $exptime=0, $flags=0)
$value
getMulti(array $keys, $flags=0)
changeTTLMulti(array $keys, $exptime, $flags=0)
see documentation in includes Linker php for Linker::makeImageLink & $time
Definition: hooks.txt:1787
if( $line===false) $args
Definition: cdb.php:64
merge( $key, callable $callback, $exptime=0, $attempts=10, $flags=0)
deleteMulti(array $keys, $flags=0)
deleteObjectsExpiringBefore( $timestamp, callable $progress=null, $limit=INF)
$params
mergeFlagMaps(array $bags)
Merge the flag maps of one or more BagOStuff objects into a "lowest common denominator" map...
Definition: BagOStuff.php:487
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not null
Definition: hooks.txt:773
makeKeyInternal( $keyspace, $args)
setMulti(array $data, $exptime=0, $flags=0)
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
changeTTL( $key, $exptime=0, $flags=0)
lock( $key, $timeout=6, $expiry=6, $rclass='')
incrWithInit( $key, $ttl, $value=1, $init=1)
makeKey( $class,... $components)
Make a cache key, scoped to this instance&#39;s keyspace.
A cache class that directs writes to one set of servers and reads to another.
addBusyCallback(callable $workCallback)