MediaWiki REL1_33
ReplicatedBagOStuff.php
Go to the documentation of this file.
1<?php
21use 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}
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
if( $line===false) $args
Definition cdb.php:64
Class representing a cache/ephemeral data store.
Definition BagOStuff.php:58
mergeFlagMaps(array $bags)
Merge the flag maps of one or more BagOStuff objects into a "lowest common denominator" map.
string $keyspace
Definition BagOStuff.php:64
A cache class that directs writes to one set of servers and reads to another.
makeGlobalKey( $class, $component=null)
Make a global cache key.
add( $key, $value, $exptime=0, $flags=0)
Insert an item if it does not already exist.
incrWithInit( $key, $ttl, $value=1, $init=1)
Increase stored value of $key by $value while preserving its TTL.
__construct( $params)
Constructor.
decr( $key, $value=1)
Decrease stored value of $key by $value while preserving its TTL.
clearLastError()
Clear the "last error" registry.
makeKey( $class, $component=null)
Make a cache key, scoped to this instance's keyspace.
incr( $key, $value=1)
Increase stored value of $key by $value while preserving its TTL.
makeKeyInternal( $keyspace, $args)
Construct a cache key.
lock( $key, $timeout=6, $expiry=6, $rclass='')
Acquire an advisory lock on a key string.
doGet( $key, $flags=0, &$casToken=null)
deleteObjectsExpiringBefore( $date, $progressCallback=false)
Delete all objects expiring before a certain date.
getLastError()
Get the "last error" registered; clearLastError() should be called manually.
deleteMulti(array $keys, $flags=0)
Batch deletion.
getMulti(array $keys, $flags=0)
Get an associative array containing the item for each of the keys that have items.
changeTTL( $key, $exptime=0, $flags=0)
Change the expiration on a key if it exists.
setMulti(array $data, $exptime=0, $flags=0)
Batch insertion/replace.
merge( $key, callable $callback, $exptime=0, $attempts=10, $flags=0)
Merge changes into the existing cache value (possibly creating a new one)
unlock( $key)
Release an advisory lock on a key string.
$data
Utility to generate mapping file used in mw.Title (phpCharToUpper.json)
processing should stop and the error should be shown to the user * false
Definition hooks.txt:187
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:37
$debug
Definition mcc.php:31
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))
$params