21 use 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 public function get( $key, $flags = 0 ) {
78 return ( $flags & self::READ_LATEST )
79 ? $this->writeStore->get( $key, $flags )
80 : $this->readStore->get( $key, $flags );
83 public function set( $key,
$value, $exptime = 0, $flags = 0 ) {
84 return $this->writeStore->set( $key,
$value, $exptime, $flags );
87 public function delete( $key, $flags = 0 ) {
88 return $this->writeStore->delete( $key, $flags );
91 public function add( $key,
$value, $exptime = 0, $flags = 0 ) {
92 return $this->writeStore->add( $key,
$value, $exptime, $flags );
95 public function merge( $key, callable $callback, $exptime = 0, $attempts = 10, $flags = 0 ) {
96 return $this->writeStore->merge( $key, $callback, $exptime, $attempts, $flags );
99 public function changeTTL( $key, $exptime = 0, $flags = 0 ) {
100 return $this->writeStore->changeTTL( $key, $exptime, $flags );
103 public function lock( $key, $timeout = 6, $expiry = 6, $rclass =
'' ) {
104 return $this->writeStore->lock( $key, $timeout, $expiry, $rclass );
108 return $this->writeStore->unlock( $key );
112 return $this->writeStore->deleteObjectsExpiringBefore( $date, $progressCallback );
116 return ( ( $flags & self::READ_LATEST ) == self::READ_LATEST )
117 ? $this->writeStore->getMulti(
$keys, $flags )
118 : $this->readStore->getMulti(
$keys, $flags );
122 return $this->writeStore->setMulti(
$data, $exptime, $flags );
126 return $this->writeStore->deleteMulti(
$keys, $flags );
130 return $this->writeStore->incr( $key,
$value );
134 return $this->writeStore->decr( $key,
$value );
138 return $this->writeStore->incrWithInit( $key, $ttl,
$value, $init );
143 ? $this->writeStore->getLastError()
144 : $this->readStore->getLastError();
148 $this->writeStore->clearLastError();
149 $this->readStore->clearLastError();
153 return $this->writeStore->makeKeyInternal( ...func_get_args() );
156 public function makeKey( $class, $component =
null ) {
157 return $this->writeStore->makeKey( ...func_get_args() );
161 return $this->writeStore->makeGlobalKey( ...func_get_args() );
164 protected function doGet( $key, $flags = 0, &$casToken =
null ) {
165 throw new LogicException( __METHOD__ .
': proxy class does not need this method.' );