49 $params[
'keyspace'] = $backend->keyspace;
50 parent::__construct( $params );
52 $this->store = $backend;
54 $this->attrMap = $backend->attrMap;
57 public function get( $key, $flags = 0 ) {
58 $value = $this->procCache->
get( $key, $flags );
59 if ( $value !==
false || $this->procCache->hasKey( $key ) ) {
63 $value = $this->store->proxyCall(
75 $valueByKeyCached = [];
78 foreach (
$keys as $key ) {
79 $value = $this->procCache->get( $key, $flags );
80 if ( $value ===
false && !$this->procCache->hasKey( $key ) ) {
83 $valueByKeyCached[$key] = $value;
87 $valueByKeyFetched = $this->store->proxyCall(
91 [ $keysFetch, $flags ]
93 $this->
setMulti( $valueByKeyFetched, self::TTL_INDEFINITE, self::WRITE_CACHE_ONLY );
95 return $valueByKeyCached + $valueByKeyFetched;
98 public function set( $key, $value, $exptime = 0, $flags = 0 ) {
99 $this->procCache->set( $key, $value, $exptime, $flags );
101 if ( $this->
fieldHasFlags( $flags, self::WRITE_CACHE_ONLY ) ) {
105 return $this->store->proxyCall( __FUNCTION__, self::ARG0_KEY, self::RES_NONKEY, func_get_args() );
108 public function delete( $key, $flags = 0 ) {
109 $this->procCache->delete( $key, $flags );
111 if ( $this->
fieldHasFlags( $flags, self::WRITE_CACHE_ONLY ) ) {
115 return $this->store->proxyCall( __FUNCTION__, self::ARG0_KEY, self::RES_NONKEY, func_get_args() );
118 public function add( $key, $value, $exptime = 0, $flags = 0 ) {
119 if ( $this->
get( $key ) ===
false ) {
120 return $this->
set( $key, $value, $exptime, $flags );
129 public function merge( $key, callable $callback, $exptime = 0, $attempts = 10, $flags = 0 ) {
130 $this->procCache->delete( $key );
132 return $this->store->proxyCall( __FUNCTION__, self::ARG0_KEY, self::RES_NONKEY, func_get_args() );
135 public function changeTTL( $key, $exptime = 0, $flags = 0 ) {
136 $this->procCache->delete( $key );
138 return $this->store->proxyCall( __FUNCTION__, self::ARG0_KEY, self::RES_NONKEY, func_get_args() );
141 public function lock( $key, $timeout = 6, $expiry = 6, $rclass =
'' ) {
142 return $this->store->proxyCall( __FUNCTION__, self::ARG0_KEY, self::RES_NONKEY, func_get_args() );
146 return $this->store->proxyCall( __FUNCTION__, self::ARG0_KEY, self::RES_NONKEY, func_get_args() );
151 callable $progress =
null,
154 $this->procCache->deleteObjectsExpiringBefore( $timestamp, $progress, $limit );
156 return $this->store->proxyCall( __FUNCTION__, self::ARG0_NONKEY, self::RES_NONKEY, func_get_args() );
163 public function makeKey( $collection, ...$components ) {
176 return $this->store->getLastError();
180 return $this->store->clearLastError();
183 public function setMulti( array $valueByKey, $exptime = 0, $flags = 0 ) {
184 $this->procCache->setMulti( $valueByKey, $exptime, $flags );
186 if ( $this->
fieldHasFlags( $flags, self::WRITE_CACHE_ONLY ) ) {
190 return $this->store->proxyCall( __FUNCTION__, self::ARG0_KEYMAP, self::RES_NONKEY, func_get_args() );
194 $this->procCache->deleteMulti(
$keys, $flags );
196 if ( $this->
fieldHasFlags( $flags, self::WRITE_CACHE_ONLY ) ) {
200 return $this->store->proxyCall( __FUNCTION__, self::ARG0_KEYARR, self::RES_NONKEY, func_get_args() );
204 $this->procCache->changeTTLMulti(
$keys, $exptime, $flags );
206 if ( $this->
fieldHasFlags( $flags, self::WRITE_CACHE_ONLY ) ) {
210 return $this->store->proxyCall( __FUNCTION__, self::ARG0_KEYARR, self::RES_NONKEY, func_get_args() );
213 public function incr( $key, $value = 1, $flags = 0 ) {
214 $this->procCache->delete( $key );
216 return $this->store->proxyCall( __FUNCTION__, self::ARG0_KEY, self::RES_NONKEY, func_get_args() );
219 public function decr( $key, $value = 1, $flags = 0 ) {
220 $this->procCache->delete( $key );
222 return $this->store->proxyCall( __FUNCTION__, self::ARG0_KEY, self::RES_NONKEY, func_get_args() );
225 public function incrWithInit( $key, $exptime, $value = 1, $init =
null, $flags = 0 ) {
226 $this->procCache->delete( $key );
228 return $this->store->proxyCall( __FUNCTION__, self::ARG0_KEY, self::RES_NONKEY, func_get_args() );
232 $this->store->addBusyCallback( $workCallback );
236 return $this->store->proxyCall( __FUNCTION__, self::ARG0_KEYMAP, self::RES_NONKEY, func_get_args() );
240 parent::setMockTime( $time );
241 $this->procCache->setMockTime( $time );
242 $this->store->setMockTime( $time );