MediaWiki  1.32.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  protected function doGet( $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 getMulti( array $keys, $flags = 0 ) {
84  return ( $flags & self::READ_LATEST )
85  ? $this->writeStore->getMulti( $keys, $flags )
86  : $this->readStore->getMulti( $keys, $flags );
87  }
88 
89  public function set( $key, $value, $exptime = 0, $flags = 0 ) {
90  return $this->writeStore->set( $key, $value, $exptime, $flags );
91  }
92 
93  public function delete( $key ) {
94  return $this->writeStore->delete( $key );
95  }
96 
97  public function add( $key, $value, $exptime = 0 ) {
98  return $this->writeStore->add( $key, $value, $exptime );
99  }
100 
101  public function incr( $key, $value = 1 ) {
102  return $this->writeStore->incr( $key, $value );
103  }
104 
105  public function decr( $key, $value = 1 ) {
106  return $this->writeStore->decr( $key, $value );
107  }
108 
109  public function lock( $key, $timeout = 6, $expiry = 6, $rclass = '' ) {
110  return $this->writeStore->lock( $key, $timeout, $expiry, $rclass );
111  }
112 
113  public function unlock( $key ) {
114  return $this->writeStore->unlock( $key );
115  }
116 
117  public function merge( $key, callable $callback, $exptime = 0, $attempts = 10, $flags = 0 ) {
118  return $this->writeStore->merge( $key, $callback, $exptime, $attempts, $flags );
119  }
120 
121  public function getLastError() {
122  return ( $this->writeStore->getLastError() != self::ERR_NONE )
123  ? $this->writeStore->getLastError()
124  : $this->readStore->getLastError();
125  }
126 
127  public function clearLastError() {
128  $this->writeStore->clearLastError();
129  $this->readStore->clearLastError();
130  }
131 
132  public function makeKeyInternal( $keyspace, $args ) {
133  return $this->writeStore->makeKeyInternal( ...func_get_args() );
134  }
135 
136  public function makeKey( $class, $component = null ) {
137  return $this->writeStore->makeKey( ...func_get_args() );
138  }
139 
140  public function makeGlobalKey( $class, $component = null ) {
141  return $this->writeStore->makeGlobalKey( ...func_get_args() );
142  }
143 }
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\getLastError
getLastError()
Get the "last error" registered; clearLastError() should be called manually.
Definition: ReplicatedBagOStuff.php:121
ReplicatedBagOStuff\makeKeyInternal
makeKeyInternal( $keyspace, $args)
Construct a cache key.
Definition: ReplicatedBagOStuff.php:132
ReplicatedBagOStuff\incr
incr( $key, $value=1)
Increase stored value of $key by $value while preserving its TTL.
Definition: ReplicatedBagOStuff.php:101
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:109
BagOStuff\ERR_NONE
const ERR_NONE
Possible values for getLastError()
Definition: BagOStuff.php:91
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:97
ReplicatedBagOStuff\clearLastError
clearLastError()
Clear the "last error" registry.
Definition: ReplicatedBagOStuff.php:127
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:140
BagOStuff\mergeFlagMaps
mergeFlagMaps(array $bags)
Merge the flag maps of one or more BagOStuff objects into a "lowest common denominator" map.
Definition: BagOStuff.php:862
$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:136
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
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:117
ReplicatedBagOStuff\unlock
unlock( $key)
Release an advisory lock on a key string.
Definition: ReplicatedBagOStuff.php:113
ReplicatedBagOStuff\doGet
doGet( $key, $flags=0)
Definition: ReplicatedBagOStuff.php:77
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:83
ReplicatedBagOStuff\decr
decr( $key, $value=1)
Decrease stored value of $key by $value while preserving its TTL.
Definition: ReplicatedBagOStuff.php:105