47 parent::__construct( $params );
55 parent::setDebug( $enabled );
56 $this->backend->setDebug( $enabled );
59 public function get( $key, $flags = 0 ) {
60 $value = $this->procCache->get( $key, $flags );
61 if ( $value ===
false && !$this->procCache->hasKey( $key ) ) {
62 $value = $this->backend->get( $key, $flags );
70 $valuesByKeyCached = [];
73 foreach (
$keys as $key ) {
74 $value = $this->procCache->get( $key, $flags );
75 if ( $value ===
false && !$this->procCache->hasKey( $key ) ) {
76 $keysMissing[] = $key;
78 $valuesByKeyCached[$key] = $value;
82 $valuesByKeyFetched = $this->backend->getMulti( $keysMissing, $flags );
83 $this->
setMulti( $valuesByKeyFetched, self::TTL_INDEFINITE, self::WRITE_CACHE_ONLY );
85 return $valuesByKeyCached + $valuesByKeyFetched;
88 public function set( $key, $value, $exptime = 0, $flags = 0 ) {
89 $this->procCache->set( $key, $value, $exptime, $flags );
91 if ( !$this->
fieldHasFlags( $flags, self::WRITE_CACHE_ONLY ) ) {
92 $this->backend->set( $key, $value, $exptime, $flags );
98 public function delete( $key, $flags = 0 ) {
99 $this->procCache->delete( $key, $flags );
101 if ( !$this->
fieldHasFlags( $flags, self::WRITE_CACHE_ONLY ) ) {
102 $this->backend->delete( $key, $flags );
108 public function add( $key, $value, $exptime = 0, $flags = 0 ) {
109 if ( $this->
get( $key ) ===
false ) {
110 return $this->
set( $key, $value, $exptime, $flags );
119 public function merge( $key, callable $callback, $exptime = 0, $attempts = 10, $flags = 0 ) {
120 $this->procCache->delete( $key );
122 return $this->backend->merge( $key, $callback, $exptime, $attempts, $flags );
125 public function changeTTL( $key, $exptime = 0, $flags = 0 ) {
126 $this->procCache->delete( $key );
128 return $this->backend->changeTTL( $key, $exptime, $flags );
131 public function lock( $key, $timeout = 6, $expiry = 6, $rclass =
'' ) {
132 return $this->backend->lock( $key, $timeout, $expiry, $rclass );
136 return $this->backend->unlock( $key );
141 callable $progress =
null,
144 $this->procCache->deleteObjectsExpiringBefore( $timestamp, $progress, $limit );
146 return $this->backend->deleteObjectsExpiringBefore( $timestamp, $progress, $limit );
150 return $this->backend->makeKeyInternal( $keyspace,
$args );
153 public function makeKey( $class, ...$components ) {
154 return $this->backend->makeKey( $class, ...$components );
158 return $this->backend->makeGlobalKey( $class, ...$components );
162 return $this->backend->getLastError();
166 return $this->backend->clearLastError();
169 public function setMulti( array $data, $exptime = 0, $flags = 0 ) {
170 $this->procCache->setMulti( $data, $exptime, $flags );
172 if ( !$this->
fieldHasFlags( $flags, self::WRITE_CACHE_ONLY ) ) {
173 return $this->backend->setMulti( $data, $exptime, $flags );
180 $this->procCache->deleteMulti(
$keys, $flags );
182 if ( !$this->
fieldHasFlags( $flags, self::WRITE_CACHE_ONLY ) ) {
183 return $this->backend->deleteMulti(
$keys, $flags );
190 $this->procCache->changeTTLMulti(
$keys, $exptime, $flags );
192 if ( !$this->
fieldHasFlags( $flags, self::WRITE_CACHE_ONLY ) ) {
193 return $this->backend->changeTTLMulti(
$keys, $exptime, $flags );
199 public function incr( $key, $value = 1, $flags = 0 ) {
200 $this->procCache->delete( $key );
202 return $this->backend->incr( $key, $value, $flags );
205 public function decr( $key, $value = 1, $flags = 0 ) {
206 $this->procCache->delete( $key );
208 return $this->backend->decr( $key, $value, $flags );
211 public function incrWithInit( $key, $exptime, $value = 1, $init =
null, $flags = 0 ) {
212 $this->procCache->delete( $key );
214 return $this->backend->incrWithInit( $key, $exptime, $value, $init, $flags );
218 $this->backend->addBusyCallback( $workCallback );
222 parent::setMockTime( $time );
223 $this->procCache->setMockTime( $time );
224 $this->backend->setMockTime( $time );