* - maxKeys : only allow this many keys (using oldest-first eviction)
*/
function __construct( $params = [] ) {
+ $params['segmentationSize'] = $params['segmentationSize'] ?? INF;
parent::__construct( $params );
$this->token = microtime( true ) . ':' . mt_rand();
}
}
- protected function doGet( $key, $flags = 0 ) {
- if ( !$this->hasKey( $key ) ) {
- return false;
- }
+ protected function doGet( $key, $flags = 0, &$casToken = null ) {
+ $casToken = null;
- if ( $this->expire( $key ) ) {
+ if ( !$this->hasKey( $key ) || $this->expire( $key ) ) {
return false;
}
unset( $this->bag[$key] );
$this->bag[$key] = $temp;
- return $this->bag[$key][self::KEY_VAL];
- }
-
- protected function getWithToken( $key, &$casToken, $flags = 0 ) {
- $casToken = null;
-
- $value = $this->doGet( $key );
- if ( $value !== false ) {
- $casToken = $this->bag[$key][self::KEY_CAS];
- }
+ $casToken = $this->bag[$key][self::KEY_CAS];
- return $value;
+ return $this->bag[$key][self::KEY_VAL];
}
- public function set( $key, $value, $exptime = 0, $flags = 0 ) {
+ protected function doSet( $key, $value, $exptime = 0, $flags = 0 ) {
// Refresh key position for maxCacheKeys eviction
unset( $this->bag[$key] );
$this->bag[$key] = [
}
public function add( $key, $value, $exptime = 0, $flags = 0 ) {
- if ( $this->get( $key ) === false ) {
- return $this->set( $key, $value, $exptime, $flags );
+ if ( $this->hasKey( $key ) && !$this->expire( $key ) ) {
+ return false; // key already set
}
- return false; // key already set
+ return $this->doSet( $key, $value, $exptime, $flags );
}
- public function delete( $key, $flags = 0 ) {
+ protected function doDelete( $key, $flags = 0 ) {
unset( $this->bag[$key] );
return true;
return false;
}
- public function merge( $key, callable $callback, $exptime = 0, $attempts = 10, $flags = 0 ) {
- return $this->mergeViaCas( $key, $callback, $exptime, $attempts, $flags );
- }
-
/**
* Clear all values in cache
*/
return false;
}
- $this->delete( $key );
+ $this->doDelete( $key );
return true;
}