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(
71 $this->
set( $key, $value, self::TTL_INDEFINITE, self::WRITE_CACHE_ONLY );
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(
210 public function makeKey( $collection, ...$components ) {
223 public function setMulti( array $valueByKey, $exptime = 0, $flags = 0 ) {
224 $this->procCache->setMulti( $valueByKey, $exptime, $flags );
226 if ( $this->
fieldHasFlags( $flags, self::WRITE_CACHE_ONLY ) ) {
230 return $this->store->proxyCall(
240 $this->procCache->deleteMulti(
$keys, $flags );
242 if ( $this->
fieldHasFlags( $flags, self::WRITE_CACHE_ONLY ) ) {
246 return $this->store->proxyCall(
256 $this->procCache->changeTTLMulti(
$keys, $exptime, $flags );
258 if ( $this->
fieldHasFlags( $flags, self::WRITE_CACHE_ONLY ) ) {
262 return $this->store->proxyCall(
271 public function incr( $key, $value = 1, $flags = 0 ) {
272 $this->procCache->delete( $key );
274 return $this->store->proxyCall(
283 public function decr( $key, $value = 1, $flags = 0 ) {
284 $this->procCache->delete( $key );
286 return $this->store->proxyCall(
295 public function incrWithInit( $key, $exptime, $step = 1, $init =
null, $flags = 0 ) {
296 $this->procCache->delete( $key );
298 return $this->store->proxyCall(
308 $this->store->addBusyCallback( $workCallback );
312 return $this->store->proxyCall(
322 parent::setMockTime( $time );
323 $this->procCache->setMockTime( $time );
324 $this->store->setMockTime( $time );
Class representing a cache/ephemeral data store.
get( $key, $flags=0)
Get an item.
genericKeyFromComponents(... $components)
At a minimum, there must be a keyspace and collection name component.
string $keyspace
Default keyspace; used by makeKey()
fieldHasFlags( $field, $flags)
Wrapper around a BagOStuff that caches data in memory.
__construct(BagOStuff $backend, $params=[])
decr( $key, $value=1, $flags=0)
Decrease stored value of $key by $value while preserving its TTL.
getMulti(array $keys, $flags=0)
Get a batch of items.
makeGlobalKey( $collection,... $components)
Make a cache key for the default keyspace and given components.
unlock( $key)
Release an advisory lock on a key string.
makeKeyInternal( $keyspace, $components)
Make a cache key for the given keyspace and components.
deleteMulti(array $keys, $flags=0)
Delete a batch of items.
makeKey( $collection,... $components)
Make a cache key for the global keyspace and given components.
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.
setNewPreparedValues(array $valueByKey)
Stage a set of new key values for storage and estimate the amount of bytes needed.
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.
addBusyCallback(callable $workCallback)
Let a callback be run to avoid wasting time on special blocking calls.
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.
incr( $key, $value=1, $flags=0)
Increase stored value of $key by $value while preserving its TTL.
convertGenericKey( $key)
Convert a "generic" reversible cache key into one for this cache.
Simple store for keeping values in an associative array for the current process.