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' );
64 protected function doGet( $key, $flags = 0, &$casToken =
null ) {
67 $blob = apcu_fetch( $key . self::KEY_SUFFIX );
69 if ( $value !==
false ) {
76 protected function doSet( $key, $value, $exptime = 0, $flags = 0 ) {
79 $success = apcu_store( $key . self::KEY_SUFFIX,
$blob, $ttl );
83 protected function doAdd( $key, $value, $exptime = 0, $flags = 0 ) {
90 protected function doDelete( $key, $flags = 0 ) {
91 apcu_delete( $key . self::KEY_SUFFIX );
96 public function incr( $key, $value = 1, $flags = 0 ) {
101 $oldCount = apcu_fetch( $key . self::KEY_SUFFIX );
102 if ( !is_int( $oldCount ) ) {
105 $count = $oldCount + (int)$value;
106 if ( apcu_cas( $key . self::KEY_SUFFIX, $oldCount, $count ) ) {
115 public function decr( $key, $value = 1, $flags = 0 ) {
120 $oldCount = apcu_fetch( $key . self::KEY_SUFFIX );
121 if ( !is_int( $oldCount ) ) {
124 $count = $oldCount - (int)$value;
125 if ( apcu_cas( $key . self::KEY_SUFFIX, $oldCount, $count ) ) {
134 public function incrWithInit( $key, $exptime, $value = 1, $init =
null, $flags = 0 ) {
135 $init = is_int( $init ) ? $init : $value;
138 if ( $value === $init && $this->useIncrTTLArg ) {
141 $result = apcu_inc( $key . self::KEY_SUFFIX, $value,
$success, $ttl );
145 $oldCount = apcu_fetch( $key . self::KEY_SUFFIX );
146 if ( $oldCount ===
false ) {
149 if ( apcu_add( $key . self::KEY_SUFFIX, $count, $ttl ) ) {
153 } elseif ( is_int( $oldCount ) ) {
154 $count = $oldCount + (int)$value;
155 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.
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.
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.
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.