49 $params[
'keyspace'] = $backend->keyspace;
50 parent::__construct( $params );
52 $this->store = $backend;
55 $this->attrMap = $backend->attrMap;
58 public function get( $key, $flags = 0 ) {
59 $value = $this->procCache->
get( $key, $flags );
60 if ( $value !==
false || $this->procCache->hasKey( $key ) ) {
64 $value = $this->store->proxyCall(
76 public function getMulti( array $keys, $flags = 0 ) {
77 $valueByKeyCached = [];
80 foreach ( $keys as $key ) {
81 $value = $this->procCache->get( $key, $flags );
82 if ( $value ===
false && !$this->procCache->hasKey( $key ) ) {
85 $valueByKeyCached[$key] = $value;
89 $valueByKeyFetched = $this->store->proxyCall(
93 [ $keysFetch, $flags ],
96 $this->
setMulti( $valueByKeyFetched, self::TTL_INDEFINITE, self::WRITE_CACHE_ONLY );
98 return $valueByKeyCached + $valueByKeyFetched;
101 public function set( $key, $value, $exptime = 0, $flags = 0 ) {
102 $this->procCache->set( $key, $value, $exptime, $flags );
104 if ( $this->
fieldHasFlags( $flags, self::WRITE_CACHE_ONLY ) ) {
108 return $this->store->proxyCall(
117 public function delete( $key, $flags = 0 ) {
118 $this->procCache->delete( $key, $flags );
120 if ( $this->
fieldHasFlags( $flags, self::WRITE_CACHE_ONLY ) ) {
124 return $this->store->proxyCall(
133 public function add( $key, $value, $exptime = 0, $flags = 0 ) {
134 if ( $this->
get( $key ) ===
false ) {
135 return $this->
set( $key, $value, $exptime, $flags );
145 public function merge( $key, callable $callback, $exptime = 0, $attempts = 10, $flags = 0 ) {
146 $this->procCache->delete( $key );
148 return $this->store->proxyCall(
157 public function changeTTL( $key, $exptime = 0, $flags = 0 ) {
158 $this->procCache->delete( $key );
160 return $this->store->proxyCall(
169 public function lock( $key, $timeout = 6, $exptime = 6, $rclass =
'' ) {
170 return $this->store->proxyCall(
180 return $this->store->proxyCall(
191 callable $progress =
null,
195 $this->procCache->deleteObjectsExpiringBefore( $timestamp, $progress, $limit, $tag );
197 return $this->store->proxyCall(
206 public function setMulti( array $valueByKey, $exptime = 0, $flags = 0 ) {
207 $this->procCache->setMulti( $valueByKey, $exptime, $flags );
209 if ( $this->
fieldHasFlags( $flags, self::WRITE_CACHE_ONLY ) ) {
213 return $this->store->proxyCall(
223 $this->procCache->deleteMulti( $keys, $flags );
225 if ( $this->
fieldHasFlags( $flags, self::WRITE_CACHE_ONLY ) ) {
229 return $this->store->proxyCall(
239 $this->procCache->changeTTLMulti( $keys, $exptime, $flags );
241 if ( $this->
fieldHasFlags( $flags, self::WRITE_CACHE_ONLY ) ) {
245 return $this->store->proxyCall(
254 public function incrWithInit( $key, $exptime, $step = 1, $init =
null, $flags = 0 ) {
255 $this->procCache->delete( $key );
257 return $this->store->proxyCall(
267 parent::setMockTime( $time );
268 $this->procCache->setMockTime( $time );
269 $this->store->setMockTime( $time );
Class representing a cache/ephemeral data store.
get( $key, $flags=0)
Get an item.
const WRITE_CACHE_ONLY
Bitfield constants for set()/merge(); these are only advisory.
fieldHasFlags( $field, $flags)
Wrapper around a BagOStuff that caches data in memory.
__construct(BagOStuff $backend, $params=[])
getMulti(array $keys, $flags=0)
Get a batch of items.
unlock( $key)
Release an advisory lock on a key string.
deleteMulti(array $keys, $flags=0)
Delete a batch of items.
deleteObjectsExpiringBefore( $timestamp, callable $progress=null, $limit=INF, string $tag=null)
Delete all objects expiring before a certain date.
changeTTLMulti(array $keys, $exptime, $flags=0)
Change the expiration of multiple items.
add( $key, $value, $exptime=0, $flags=0)
Insert an item if it does not already exist.
lock( $key, $timeout=6, $exptime=6, $rclass='')
Acquire an advisory lock on a key string, exclusive to the caller.
changeTTL( $key, $exptime=0, $flags=0)
Change the expiration on an item.
merge( $key, callable $callback, $exptime=0, $attempts=10, $flags=0)
Merge changes into the existing cache value (possibly creating a new one)
setMulti(array $valueByKey, $exptime=0, $flags=0)
Set a batch of items.
incrWithInit( $key, $exptime, $step=1, $init=null, $flags=0)
Increase the value of the given key (no TTL change) if it exists or create it otherwise.
Simple store for keeping values in an associative array for the current process.