21use Wikimedia\ObjectFactory;
53 if ( !isset(
$params[
'writeFactory'] ) ) {
54 throw new InvalidArgumentException(
55 __METHOD__ .
': the "writeFactory" parameter is required' );
57 if ( !isset(
$params[
'readFactory'] ) ) {
58 throw new InvalidArgumentException(
59 __METHOD__ .
': the "readFactory" parameter is required' );
62 $opts = [
'reportDupes' =>
false ];
65 : ObjectFactory::getObjectFromSpec( $opts +
$params[
'writeFactory'] );
68 : ObjectFactory::getObjectFromSpec( $opts +
$params[
'readFactory'] );
69 $this->attrMap = $this->
mergeFlagMaps( [ $this->readStore, $this->writeStore ] );
73 $this->writeStore->setDebug(
$debug );
74 $this->readStore->setDebug(
$debug );
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 );
84 return ( $flags & self::READ_LATEST )
85 ? $this->writeStore->getMulti(
$keys, $flags )
86 : $this->readStore->getMulti(
$keys, $flags );
89 public function set( $key,
$value, $exptime = 0, $flags = 0 ) {
90 return $this->writeStore->set( $key,
$value, $exptime, $flags );
93 public function delete( $key ) {
94 return $this->writeStore->delete( $key );
98 return $this->writeStore->add( $key,
$value, $exptime );
102 return $this->writeStore->incr( $key,
$value );
106 return $this->writeStore->decr( $key,
$value );
109 public function lock( $key, $timeout = 6, $expiry = 6, $rclass =
'' ) {
110 return $this->writeStore->lock( $key, $timeout, $expiry, $rclass );
114 return $this->writeStore->unlock( $key );
117 public function merge( $key, callable $callback, $exptime = 0, $attempts = 10, $flags = 0 ) {
118 return $this->writeStore->merge( $key, $callback, $exptime, $attempts, $flags );
122 return ( $this->writeStore->getLastError() != self::ERR_NONE )
123 ? $this->writeStore->getLastError()
124 : $this->readStore->getLastError();
128 $this->writeStore->clearLastError();
129 $this->readStore->clearLastError();
interface is intended to be more or less compatible with the PHP memcached client.
mergeFlagMaps(array $bags)
Merge the flag maps of one or more BagOStuff objects into a "lowest common denominator" map.
A cache class that directs writes to one set of servers and reads to another.
__construct( $params)
Constructor.
decr( $key, $value=1)
Decrease stored value of $key by $value while preserving its TTL.
add( $key, $value, $exptime=0)
clearLastError()
Clear the "last error" registry.
incr( $key, $value=1)
Increase stored value of $key by $value while preserving its TTL.
lock( $key, $timeout=6, $expiry=6, $rclass='')
Acquire an advisory lock on a key string.
getLastError()
Get the "last error" registered; clearLastError() should be called manually.
getMulti(array $keys, $flags=0)
Get an associative array containing the item for each of the keys that have items.
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.
processing should stop and the error should be shown to the user * false