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 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 );
123 ? $this->writeStore->getLastError()
124 : $this->readStore->getLastError();
128 $this->writeStore->clearLastError();
129 $this->readStore->clearLastError();
133 return $this->writeStore->makeKeyInternal( ...func_get_args() );
136 public function makeKey( $class, $component =
null ) {
137 return $this->writeStore->makeKey( ...func_get_args() );
141 return $this->writeStore->makeGlobalKey( ...func_get_args() );