47 private const KEY_SUFFIX =
':4';
53 $params[
'segmentationSize'] = $params[
'segmentationSize'] ?? INF;
54 parent::__construct( $params );
56 $this->nativeSerialize = ( ini_get(
'apc.serializer' ) !==
'default' );
57 $this->useIncrTTLArg = version_compare( phpversion(
'apcu' ),
'5.1.12',
'>=' );
61 ini_set(
'apc.use_request_time',
'0' );
63 if ( PHP_SAPI ===
'cli' ) {
72 protected function doGet( $key, $flags = 0, &$casToken =
null ) {
73 $getToken = ( $casToken === self::PASS_BY_REF );
76 $blob = apcu_fetch( $key . self::KEY_SUFFIX );
78 if ( $getToken && $value !==
false ) {
85 protected function doSet( $key, $value, $exptime = 0, $flags = 0 ) {
88 $success = apcu_store( $key . self::KEY_SUFFIX,
$blob, $ttl );
92 protected function doAdd( $key, $value, $exptime = 0, $flags = 0 ) {
99 protected function doDelete( $key, $flags = 0 ) {
100 apcu_delete( $key . self::KEY_SUFFIX );
105 public function incr( $key, $value = 1, $flags = 0 ) {
110 $oldCount = apcu_fetch( $key . self::KEY_SUFFIX );
111 if ( !is_int( $oldCount ) ) {
114 $count = $oldCount + (int)$value;
115 if ( apcu_cas( $key . self::KEY_SUFFIX, $oldCount, $count ) ) {
124 public function decr( $key, $value = 1, $flags = 0 ) {
129 $oldCount = apcu_fetch( $key . self::KEY_SUFFIX );
130 if ( !is_int( $oldCount ) ) {
133 $count = $oldCount - (int)$value;
134 if ( apcu_cas( $key . self::KEY_SUFFIX, $oldCount, $count ) ) {
143 public function incrWithInit( $key, $exptime, $value = 1, $init =
null, $flags = 0 ) {
144 $init = is_int( $init ) ? $init : $value;
147 if ( $value === $init && $this->useIncrTTLArg ) {
150 $result = apcu_inc( $key . self::KEY_SUFFIX, $value,
$success, $ttl );
154 $oldCount = apcu_fetch( $key . self::KEY_SUFFIX );
155 if ( $oldCount ===
false ) {
158 if ( apcu_add( $key . self::KEY_SUFFIX, $count, $ttl ) ) {
162 } elseif ( is_int( $oldCount ) ) {
163 $count = $oldCount + (int)$value;
164 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.
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.
makeKeyInternal( $keyspace, $components)
Make a cache key for the given keyspace and components.
decr( $key, $value=1, $flags=0)
Decrease stored value of $key by $value while preserving its TTL.
doSet( $key, $value, $exptime=0, $flags=0)
Set an item.
doDelete( $key, $flags=0)
Delete an item.
bool $nativeSerialize
Whether to trust the APC implementation to serialization.
convertGenericKey( $key)
Convert a "generic" reversible cache key into one for this cache.
static int $CAS_MAX_ATTEMPTS
Max attempts for implicit CAS operations.
__construct(array $params=[])
doGet( $key, $flags=0, &$casToken=null)
incr( $key, $value=1, $flags=0)
Increase stored value of $key by $value while preserving its TTL.
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.
getSerialized( $value, $key)
Get the serialized form a value, using any applicable prepared value.
getExpirationAsTTL( $exptime)
Convert an optionally absolute expiry time to a relative time.