Go to the documentation of this file.
29 use Psr\Log\LoggerAwareInterface;
30 use Psr\Log\LoggerInterface;
31 use Psr\Log\NullLogger;
32 use Wikimedia\ScopedCallback;
97 $this->
setLogger( $params[
'logger'] ??
new NullLogger() );
98 $this->asyncHandler = $params[
'asyncHandler'] ??
null;
113 $this->debugMode = $enabled;
130 $value = $this->
get( $key, $flags );
132 if ( $value ===
false ) {
133 $value = $callback( $ttl );
134 if ( $value !==
false && $ttl >= 0 ) {
135 $this->
set( $key, $value, $ttl, $flags );
155 abstract public function get( $key, $flags = 0 );
166 abstract public function set( $key, $value, $exptime = 0, $flags = 0 );
179 abstract public function delete( $key, $flags = 0 );
190 abstract public function add( $key, $value, $exptime = 0, $flags = 0 );
209 abstract public function merge(
234 abstract public function changeTTL( $key, $exptime = 0, $flags = 0 );
247 abstract public function lock( $key, $timeout = 6, $expiry = 6, $rclass =
'' );
255 abstract public function unlock( $key );
273 final public function getScopedLock( $key, $timeout = 6, $expiry = 30, $rclass =
'' ) {
274 $expiry = min( $expiry ?: INF, self::TTL_DAY );
276 if ( !$this->
lock( $key, $timeout, $expiry, $rclass ) ) {
282 return new ScopedCallback(
function () use ( $key, $lSince, $expiry ) {
285 if ( ( $age + $latency ) >= $expiry ) {
286 $this->logger->warning(
287 "Lock for {key} held too long ({age} sec).",
288 [
'key' => $key,
'age' => $age ]
308 callable $progress =
null,
318 abstract public function getMulti( array
$keys, $flags = 0 );
333 abstract public function setMulti( array $data, $exptime = 0, $flags = 0 );
369 abstract public function incr( $key, $value = 1, $flags = 0 );
378 abstract public function decr( $key, $value = 1, $flags = 0 );
395 abstract public function incrWithInit( $key, $exptime, $value = 1, $init =
null, $flags = 0 );
450 abstract public function makeGlobalKey( $class, ...$components );
460 abstract public function makeKey( $class, ...$components );
494 return ( ( $field & $flags ) === $flags );
505 foreach ( $bags as $bag ) {
506 foreach ( $bag->attrMap as $attr => $rank ) {
507 if ( isset( $map[$attr] ) ) {
508 $map[$attr] = min( $map[$attr], $rank );
524 return $this->wallClockOverride ?: microtime(
true );
533 $this->wallClockOverride =& $time;
getSegmentedValueMaxSize()
getLastError()
Get the "last error" registered; clearLastError() should be called manually.
add( $key, $value, $exptime=0, $flags=0)
Insert an item if it does not already exist.
const WRITE_SYNC
Bitfield constants for set()/merge(); these are only advisory.
const WRITE_ALLOW_SEGMENTS
Class representing a cache/ephemeral data store.
changeTTL( $key, $exptime=0, $flags=0)
Change the expiration on a key if it exists.
makeGlobalKey( $class,... $components)
Make a global cache key.
changeTTLMulti(array $keys, $exptime, $flags=0)
Change the expiration of multiple keys that exist.
getWithSetCallback( $key, $ttl, $callback, $flags=0)
Get an item with the given key, regenerating and setting it if not found.
unlock( $key)
Release an advisory lock on a key string.
clearLastError()
Clear the "last error" registry.
decr( $key, $value=1, $flags=0)
Decrease stored value of $key by $value while preserving its TTL.
Generic interface for lightweight expiring object stores.
incr( $key, $value=1, $flags=0)
Increase stored value of $key by $value while preserving its TTL.
setLogger(LoggerInterface $logger)
callable null $asyncHandler
const READ_LATEST
Bitfield constants for get()/getMulti(); these are only advisory.
addBusyCallback(callable $workCallback)
Let a callback be run to avoid wasting time on special blocking calls.
float null $wallClockOverride
const WRITE_PRUNE_SEGMENTS
mergeFlagMaps(array $bags)
Merge the flag maps of one or more BagOStuff objects into a "lowest common denominator" map.
__construct(array $params=[])
Parameters include:
merge( $key, callable $callback, $exptime=0, $attempts=10, $flags=0)
Merge changes into the existing cache value (possibly creating a new one)
setMulti(array $data, $exptime=0, $flags=0)
Batch insertion/replace.
deleteMulti(array $keys, $flags=0)
Batch deletion.
makeKey( $class,... $components)
Make a cache key, scoped to this instance's keyspace.
incrWithInit( $key, $exptime, $value=1, $init=null, $flags=0)
Increase the value of the given key (no TTL change) if it exists or create it otherwise.
int[] $attrMap
Map of (ATTR_* class constant => QOS_* class constant)
fieldHasFlags( $field, $flags)
lock( $key, $timeout=6, $expiry=6, $rclass='')
Acquire an advisory lock on a key string.
deleteObjectsExpiringBefore( $timestamp, callable $progress=null, $limit=INF)
Delete all objects expiring before a certain date.
Generic interface for object stores with key encoding methods.
makeKeyInternal( $keyspace, $args)
Construct a cache key.
getScopedLock( $key, $timeout=6, $expiry=30, $rclass='')
Get a lightweight exclusive self-unlocking lock.
getMulti(array $keys, $flags=0)
Get an associative array containing the item for each of the keys that have items.