23 use Wikimedia\ObjectFactory;
66 if ( empty(
$params[
'caches'] ) || !is_array(
$params[
'caches'] ) ) {
67 throw new InvalidArgumentException(
68 __METHOD__ .
': "caches" parameter must be an array of caches'
73 foreach (
$params[
'caches']
as $cacheInfo ) {
75 $this->caches[] = $cacheInfo;
77 if ( !isset( $cacheInfo[
'args'] ) ) {
82 $cacheInfo[
'args'] = [ $cacheInfo ];
84 $this->caches[] = ObjectFactory::getObjectFromSpec( $cacheInfo );
89 $this->asyncWrites = (
90 isset(
$params[
'replication'] ) &&
91 $params[
'replication'] ===
'async' &&
92 is_callable( $this->asyncHandler )
97 foreach ( $this->caches
as $cache ) {
102 protected function doGet( $key, $flags = 0 ) {
103 if ( ( $flags & self::READ_LATEST ) == self::READ_LATEST ) {
107 return $this->caches[0]->get( $key, $flags );
112 foreach ( $this->caches
as $cache ) {
122 && ( $flags & self::READ_VERIFIED ) == self::READ_VERIFIED
124 $this->
doWrite( $misses, $this->asyncWrites,
'set', $key,
$value, self::UPGRADE_TTL );
130 public function set( $key,
$value, $exptime = 0, $flags = 0 ) {
138 public function delete( $key ) {
139 return $this->
doWrite( self::ALL, $this->asyncWrites,
'delete', $key );
143 return $this->
doWrite( self::ALL, $this->asyncWrites,
'add', $key,
$value, $exptime );
147 return $this->
doWrite( self::ALL, $this->asyncWrites,
'incr', $key,
$value );
151 return $this->
doWrite( self::ALL, $this->asyncWrites,
'decr', $key,
$value );
154 public function lock( $key, $timeout = 6, $expiry = 6, $rclass =
'' ) {
156 return $this->caches[0]->lock( $key, $timeout, $expiry, $rclass );
161 return $this->caches[0]->unlock( $key );
165 return $this->caches[0]->getLastError();
169 $this->caches[0]->clearLastError();
183 $args = array_slice( func_get_args(), 3 );
191 foreach ( $this->caches
as $i =>
$cache ) {
192 if ( $i >= $count ) {
198 if ( !call_user_func_array( [
$cache, $method ],
$args ) ) {
207 if ( !call_user_func_array( [
$cache, $method ],
$args ) ) {
208 $logger->warning(
"Async $method op failed" );
228 foreach ( $this->caches
as $cache ) {
229 if (
$cache->deleteObjectsExpiringBefore( $date, $progressCallback ) ) {
237 public function makeKey( $class, $component =
null ) {
238 return call_user_func_array( [ $this->caches[0], __FUNCTION__ ], func_get_args() );
242 return call_user_func_array( [ $this->caches[0], __FUNCTION__ ], func_get_args() );