23use Wikimedia\ObjectFactory;
65 if ( empty(
$params[
'caches'] ) || !is_array(
$params[
'caches'] ) ) {
66 throw new InvalidArgumentException(
67 __METHOD__ .
': "caches" parameter must be an array of caches'
72 foreach (
$params[
'caches'] as $cacheInfo ) {
74 $this->caches[] = $cacheInfo;
76 if ( !isset( $cacheInfo[
'args'] ) ) {
81 $cacheInfo[
'args'] = [ $cacheInfo ];
83 $this->caches[] = ObjectFactory::getObjectFromSpec( $cacheInfo );
88 $this->asyncWrites = (
89 isset(
$params[
'replication'] ) &&
90 $params[
'replication'] ===
'async' &&
91 is_callable( $this->asyncHandler )
94 $this->cacheIndexes = array_keys( $this->caches );
98 foreach ( $this->caches as
$cache ) {
103 protected function doGet( $key, $flags = 0 ) {
104 if ( ( $flags & self::READ_LATEST ) == self::READ_LATEST ) {
108 return $this->caches[0]->get( $key, $flags );
113 foreach ( $this->caches as $i =>
$cache ) {
123 && ( $flags & self::READ_VERIFIED ) == self::READ_VERIFIED
127 $missIndexes, $this->asyncWrites,
'set', $key,
$value, self::UPGRADE_TTL
134 public function set( $key,
$value, $exptime = 0, $flags = 0 ) {
142 public function delete( $key ) {
143 return $this->
doWrite( $this->cacheIndexes, $this->asyncWrites,
'delete', $key );
148 $ok = $this->
doWrite( [ 0 ], $this->asyncWrites,
'add', $key,
$value, $exptime );
154 array_slice( $this->cacheIndexes, 1 ),
167 return $this->
doWrite( $this->cacheIndexes, $this->asyncWrites,
'incr', $key,
$value );
171 return $this->
doWrite( $this->cacheIndexes, $this->asyncWrites,
'decr', $key,
$value );
174 public function merge( $key, callable $callback, $exptime = 0, $attempts = 10, $flags = 0 ) {
191 public function lock( $key, $timeout = 6, $expiry = 6, $rclass =
'' ) {
193 return $this->caches[0]->lock( $key, $timeout, $expiry, $rclass );
198 return $this->caches[0]->unlock( $key );
202 return $this->caches[0]->getLastError();
206 $this->caches[0]->clearLastError();
220 $args = array_slice( func_get_args(), 3 );
222 if ( array_diff( $indexes, [ 0 ] ) &&
$asyncWrites && $method !==
'merge' ) {
228 foreach ( $indexes as $i ) {
229 $cache = $this->caches[$i];
232 if ( !
$cache->$method( ...$args ) ) {
240 if ( !
$cache->$method( ...$args ) ) {
241 $logger->warning(
"Async $method op failed" );
261 foreach ( $this->caches as
$cache ) {
262 if (
$cache->deleteObjectsExpiringBefore( $date, $progressCallback ) ) {
271 return $this->caches[0]->makeKeyInternal( ...func_get_args() );
274 public function makeKey( $class, $component =
null ) {
275 return $this->caches[0]->makeKey( ...func_get_args() );
279 return $this->caches[0]->makeGlobalKey( ...func_get_args() );
unserialize( $serialized)
Class representing a cache/ephemeral data store.
callback null $asyncHandler
const WRITE_SYNC
Bitfield constants for set()/merge()
mergeFlagMaps(array $bags)
Merge the flag maps of one or more BagOStuff objects into a "lowest common denominator" map.
A cache class that replicates all writes to multiple child caches.
doWrite( $indexes, $asyncWrites, $method)
Apply a write method to the backing caches specified by $indexes (in order)
add( $key, $value, $exptime=0)
int[] $cacheIndexes
List of all backing cache indexes.
getLastError()
Get the "last error" registered; clearLastError() should be called manually.
__construct( $params)
$params include:
clearLastError()
Clear the "last error" registry.
incr( $key, $value=1)
Increase stored value of $key by $value while preserving its TTL.
merge( $key, callable $callback, $exptime=0, $attempts=10, $flags=0)
Merge changes into the existing cache value (possibly creating a new one)
makeGlobalKey( $class, $component=null)
Make a global cache key.
bool $asyncWrites
Use async secondary writes.
makeKeyInternal( $keyspace, $args)
Construct a cache key.
lock( $key, $timeout=6, $expiry=6, $rclass='')
Acquire an advisory lock on a key string.
makeKey( $class, $component=null)
Make a cache key, scoped to this instance's keyspace.
deleteObjectsExpiringBefore( $date, $progressCallback=false)
Delete objects expiring before a certain date.
decr( $key, $value=1)
Decrease stored value of $key by $value while preserving its TTL.
unlock( $key)
Release an advisory lock on a key string.
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses & $ret
processing should stop and the error should be shown to the user * false
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use