42 private const KEY_SUFFIX =
':5';
45 private static $CAS_MAX_ATTEMPTS = 100;
49 $params[
'segmentationSize'] = INF;
50 parent::__construct( $params );
55 ini_set(
'apc.use_request_time',
'0' );
57 if ( PHP_SAPI ===
'cli' ) {
58 $this->attrMap[self::ATTR_DURABILITY] = ini_get(
'apc.enable_cli' )
59 ? self::QOS_DURABILITY_SCRIPT
60 : self::QOS_DURABILITY_NONE;
62 $this->attrMap[self::ATTR_DURABILITY] = self::QOS_DURABILITY_SERVICE;
66 protected function doGet( $key, $flags = 0, &$casToken =
null ) {
67 $getToken = ( $casToken === self::PASS_BY_REF );
70 $value = apcu_fetch( $key . self::KEY_SUFFIX );
71 if ( $getToken && $value !==
false ) {
80 protected function doSet( $key, $value, $exptime = 0, $flags = 0 ) {
83 return apcu_store( $key . self::KEY_SUFFIX, $value, $ttl );
86 protected function doAdd( $key, $value, $exptime = 0, $flags = 0 ) {
87 if ( apcu_exists( $key . self::KEY_SUFFIX ) ) {
94 return apcu_add( $key . self::KEY_SUFFIX, $value, $ttl );
97 protected function doDelete( $key, $flags = 0 ) {
98 apcu_delete( $key . self::KEY_SUFFIX );
106 if ( $step === $init ) {
109 $result = apcu_inc( $key . self::KEY_SUFFIX, $step,
$success, $ttl );
112 for ( $i = 0; $i < self::$CAS_MAX_ATTEMPTS; ++$i ) {
113 $oldCount = apcu_fetch( $key . self::KEY_SUFFIX );
114 if ( $oldCount ===
false ) {
117 if ( apcu_add( $key . self::KEY_SUFFIX, $count, $ttl ) ) {
121 } elseif ( is_int( $oldCount ) ) {
122 $count = $oldCount + $step;
123 if ( apcu_cas( $key . self::KEY_SUFFIX, $oldCount, $count ) ) {
This is a wrapper for APCu's shared memory functions.
doAdd( $key, $value, $exptime=0, $flags=0)
Insert an item if it does not already exist.
doIncrWithInit( $key, $exptime, $step, $init, $flags)
makeKeyInternal( $keyspace, $components)
Make a cache key for the given keyspace and components.
doSet( $key, $value, $exptime=0, $flags=0)
Set an item.
doDelete( $key, $flags=0)
Delete an item.
convertGenericKey( $key)
Convert a "generic" reversible cache key into one for this cache.
__construct(array $params=[])
doGet( $key, $flags=0, &$casToken=null)
Get an item.
genericKeyFromComponents(... $components)
At a minimum, there must be a keyspace and collection name component.
string $keyspace
Default keyspace; used by makeKey()
Storage medium specific cache for storing items (e.g.
getExpirationAsTTL( $exptime)
Convert an optionally absolute expiry time to a relative time.