protected $caches;
/** @var bool Use async secondary writes */
protected $asyncWrites = false;
- /** @var callback|null */
- protected $asyncHandler;
/** Idiom for "write to all backends" */
const ALL = INF;
* only use the primary store.
* - replication: Either 'sync' or 'async'. This controls whether writes
* to secondary stores are deferred when possible. Async writes
- * require setting 'asyncCallback'. HHVM register_postsend_function() function.
+ * require setting 'asyncHandler'. HHVM register_postsend_function() function.
* Async writes can increase the chance of some race conditions
* or cause keys to expire seconds later than expected. It is
* safe to use for modules when cached values: are immutable,
* invalidation uses logical TTLs, invalidation uses etag/timestamp
* validation against the DB, or merge() is used to handle races.
- * - asyncHandler: callable that takes a callback and runs it after the
- * current web request ends. In CLI mode, it should run it immediately.
* @param array $params
* @throws InvalidArgumentException
*/
);
}
- $this->caches = array();
+ $this->caches = [];
foreach ( $params['caches'] as $cacheInfo ) {
if ( $cacheInfo instanceof BagOStuff ) {
$this->caches[] = $cacheInfo;
// Callers intenting this to be for ObjectFactory::getObjectFromSpec
// should have set "args" per the docs above. Doings so avoids extra
// (likely harmless) params (factory/class/calls) ending up in "args".
- $cacheInfo['args'] = array( $cacheInfo );
+ $cacheInfo['args'] = [ $cacheInfo ];
}
$this->caches[] = ObjectFactory::getObjectFromSpec( $cacheInfo );
}
}
+ $this->mergeFlagMaps( $this->caches );
- $this->asyncHandler = isset( $params['asyncHandler'] )
- ? $params['asyncHandler']
- : null;
$this->asyncWrites = (
isset( $params['replication'] ) &&
$params['replication'] === 'async' &&
if ( $i == 0 || !$asyncWrites ) {
// First store or in sync mode: write now and get result
- if ( !call_user_func_array( array( $cache, $method ), $args ) ) {
+ if ( !call_user_func_array( [ $cache, $method ], $args ) ) {
$ret = false;
}
} else {
call_user_func(
$this->asyncHandler,
function () use ( $cache, $method, $args, $logger ) {
- if ( !call_user_func_array( array( $cache, $method ), $args ) ) {
+ if ( !call_user_func_array( [ $cache, $method ], $args ) ) {
$logger->warning( "Async $method op failed" );
}
}