55 $params[
'segmentationSize'] = $params[
'segmentationSize'] ?? INF;
56 parent::__construct( $params );
58 $this->token = microtime(
true ) .
':' . mt_rand();
59 $this->maxCacheKeys = $params[
'maxKeys'] ?? INF;
60 if ( $this->maxCacheKeys <= 0 ) {
61 throw new InvalidArgumentException(
'$maxKeys parameter must be above zero' );
65 protected function doGet( $key, $flags = 0, &$casToken =
null ) {
73 $temp = $this->bag[$key];
74 unset( $this->bag[$key] );
75 $this->bag[$key] = $temp;
82 protected function doSet( $key, $value, $exptime = 0, $flags = 0 ) {
84 unset( $this->bag[$key] );
86 self::KEY_VAL => $value,
91 if ( count( $this->bag ) > $this->maxCacheKeys ) {
93 $evictKey = key( $this->bag );
94 unset( $this->bag[$evictKey] );
100 protected function doAdd( $key, $value, $exptime = 0, $flags = 0 ) {
101 if ( $this->
hasKey( $key ) && !$this->
expire( $key ) ) {
105 return $this->
doSet( $key, $value, $exptime, $flags );
109 unset( $this->bag[$key] );
114 public function incr( $key, $value = 1, $flags = 0 ) {
115 $n = $this->
get( $key );
117 $n = max( $n + (
int)$value, 0 );
126 public function decr( $key, $value = 1, $flags = 0 ) {
127 return $this->
incr( $key, -$value, $flags );
143 if ( $et == self::TTL_INDEFINITE || $et > $this->
getCurrentTime() ) {
160 return isset( $this->bag[$key] );