26use InvalidArgumentException;
46 private static $casCounter = 0;
62 $params[
'segmentationSize'] ??= INF;
65 $this->token = microtime(
true ) .
':' . mt_rand();
66 $maxKeys =
$params[
'maxKeys'] ?? INF;
67 if ( $maxKeys !== INF && ( !is_int( $maxKeys ) || $maxKeys <= 0 ) ) {
68 throw new InvalidArgumentException(
'$maxKeys parameter must be above zero' );
70 $this->maxCacheKeys = $maxKeys;
75 protected function doGet( $key, $flags = 0, &$casToken =
null ) {
84 $temp = $this->bag[$key];
85 unset( $this->bag[$key] );
86 $this->bag[$key] = $temp;
89 if ( $getToken && $value !==
false ) {
96 protected function doSet( $key, $value, $exptime = 0, $flags = 0 ) {
98 unset( $this->bag[$key] );
100 self::KEY_VAL => $value,
102 self::KEY_CAS => $this->token .
':' . ++self::$casCounter
105 if ( count( $this->bag ) > $this->maxCacheKeys ) {
106 $evictKey = array_key_first( $this->bag );
107 unset( $this->bag[$evictKey] );
113 protected function doAdd( $key, $value, $exptime = 0, $flags = 0 ) {
114 if ( $this->
hasKey( $key ) && !$this->
expire( $key ) ) {
119 return $this->
doSet( $key, $value, $exptime, $flags );
123 unset( $this->bag[$key] );
129 $curValue = $this->
doGet( $key );
130 if ( $curValue ===
false ) {
131 $newValue = $this->
doSet( $key, $init, $exptime ) ? $init :
false;
132 } elseif ( $this->
isInteger( $curValue ) ) {
133 $newValue = max( $curValue + $step, 0 );
156 if ( $et == self::TTL_INDEFINITE || $et > $this->
getCurrentTime() ) {
174 return isset( $this->bag[$key] );
179class_alias( HashBagOStuff::class,
'HashBagOStuff' );
array $params
The job parameters.