56 $params[
'segmentationSize'] = $params[
'segmentationSize'] ?? INF;
57 parent::__construct( $params );
59 $this->token = microtime(
true ) .
':' . mt_rand();
60 $maxKeys = $params[
'maxKeys'] ?? INF;
61 if ( $maxKeys !== INF && ( !is_int( $maxKeys ) || $maxKeys <= 0 ) ) {
62 throw new InvalidArgumentException(
'$maxKeys parameter must be above zero' );
64 $this->maxCacheKeys = $maxKeys;
69 protected function doGet( $key, $flags = 0, &$casToken =
null ) {
70 $getToken = ( $casToken === self::PASS_BY_REF );
78 $temp = $this->bag[$key];
79 unset( $this->bag[$key] );
80 $this->bag[$key] = $temp;
83 if ( $getToken && $value !==
false ) {
90 protected function doSet( $key, $value, $exptime = 0, $flags = 0 ) {
92 unset( $this->bag[$key] );
94 self::KEY_VAL => $value,
99 if ( count( $this->bag ) > $this->maxCacheKeys ) {
101 $evictKey = key( $this->bag );
102 unset( $this->bag[$evictKey] );
108 protected function doAdd( $key, $value, $exptime = 0, $flags = 0 ) {
109 if ( $this->
hasKey( $key ) && !$this->
expire( $key ) ) {
113 return $this->
doSet( $key, $value, $exptime, $flags );
117 unset( $this->bag[$key] );
122 public function incr( $key, $value = 1, $flags = 0 ) {
123 return $this->
doIncr( $key, $value, $flags );
126 public function decr( $key, $value = 1, $flags = 0 ) {
127 return $this->
doIncr( $key, -$value, $flags );
130 private function doIncr( $key, $value = 1, $flags = 0 ) {
131 $n = $this->
doGet( $key );
133 $n = max( $n + (
int)$value, 0 );
143 $curValue = $this->
doGet( $key );
144 if ( $curValue ===
false ) {
145 $newValue = $this->
doSet( $key, $init, $exptime ) ? $init :
false;
146 } elseif ( $this->
isInteger( $curValue ) ) {
147 $newValue = max( $curValue + $step, 0 );
169 if ( $et == self::TTL_INDEFINITE || $et > $this->
getCurrentTime() ) {
191 return isset( $this->bag[$key] );
genericKeyFromComponents(... $components)
At a minimum, there must be a keyspace and collection name component.
string $keyspace
Default keyspace; used by makeKey()
Simple store for keeping values in an associative array for the current process.
int double $maxCacheKeys
Max entries allowed, INF for unlimited.
string $token
CAS token prefix for this instance.
setNewPreparedValues(array $valueByKey)
Stage a set of new key values for storage and estimate the amount of bytes needed.
convertGenericKey( $key)
Convert a "generic" reversible cache key into one for this cache.
clear()
Clear all values in cache.
decr( $key, $value=1, $flags=0)
Decrease stored value of $key by $value while preserving its TTL.
makeKeyInternal( $keyspace, $components)
Make a cache key for the given keyspace and components.
incr( $key, $value=1, $flags=0)
Increase stored value of $key by $value while preserving its TTL.
doIncrWithInit( $key, $exptime, $step, $init, $flags)
hasKey( $key)
Does this bag have a non-null value for the given key?
doAdd( $key, $value, $exptime=0, $flags=0)
Insert an item if it does not already exist.
doDelete( $key, $flags=0)
Delete an item.
doIncr( $key, $value=1, $flags=0)
doGet( $key, $flags=0, &$casToken=null)
Get an item.
doSet( $key, $value, $exptime=0, $flags=0)
Set an item.
static int $casCounter
CAS token counter.
Storage medium specific cache for storing items (e.g.
getExpirationAsTimestamp( $exptime)
Convert an optionally relative timestamp to an absolute time.
isInteger( $value)
Check if a value is an integer.
guessSerialSizeOfValues(array $values)
Estimate the size of a each variable once serialized.