32 $params[
'segmentationSize'] = $params[
'segmentationSize'] ?? INF;
33 parent::__construct( $params );
35 if ( PHP_SAPI ===
'cli' ) {
36 $this->attrMap[self::ATTR_DURABILITY] = ini_get(
'wincache.enablecli' )
37 ? self::QOS_DURABILITY_SCRIPT
38 : self::QOS_DURABILITY_NONE;
40 $this->attrMap[self::ATTR_DURABILITY] = self::QOS_DURABILITY_SERVICE;
44 protected function doGet( $key, $flags = 0, &$casToken =
null ) {
45 $getToken = ( $casToken === self::PASS_BY_REF );
48 $data = wincache_ucache_get( $key );
49 if ( !is_string( $data ) && !is_int( $data ) ) {
54 if ( $getToken && $value !==
false ) {
61 protected function doCas( $casToken, $key, $value, $exptime = 0, $flags = 0 ) {
63 if ( !wincache_lock( $key ) ) {
67 $curCasToken = self::PASS_BY_REF;
68 $this->
doGet( $key, self::READ_LATEST, $curCasToken );
69 if ( $casToken === $curCasToken ) {
70 $success = $this->
set( $key, $value, $exptime, $flags );
73 __METHOD__ .
' failed due to race condition for {key}.',
81 wincache_unlock( $key );
86 protected function doSet( $key, $value, $exptime = 0, $flags = 0 ) {
88 $result = wincache_ucache_set( $key, $this->
getSerialized( $value, $key ), $ttl );
93 return ( $result === [] || $result ===
true );
96 protected function doAdd( $key, $value, $exptime = 0, $flags = 0 ) {
97 if ( wincache_ucache_exists( $key ) ) {
103 $result = wincache_ucache_add( $key, $this->
getSerialized( $value, $key ), $ttl );
108 return ( $result === [] || $result ===
true );
112 wincache_ucache_delete( $key );
123 $charsLeft = 125 - strlen(
$keyspace ) - count( $components );
125 $components = array_map(
126 static function ( $component ) use ( &$charsLeft ) {
128 if ( $charsLeft > 33 && strlen( $component ) > $charsLeft ) {
129 $component =
'#' . md5( $component );
132 $charsLeft -= strlen( $component );
138 if ( $charsLeft < 0 ) {
139 return $keyspace .
':BagOStuff-long-key:##' . md5( implode(
':', $components ) );
142 return $keyspace .
':' . implode(
':', $components );
147 if ( !wincache_lock( $key ) ) {
151 $curValue = $this->
doGet( $key );
152 if ( $curValue ===
false ) {
153 $newValue = $this->
doSet( $key, $init, $exptime ) ? $init :
false;
154 } elseif ( $this->
isInteger( $curValue ) ) {
155 $sum = max( $curValue + $step, 0 );
156 $oldTTL = wincache_ucache_info(
false, $key )[
"ucache_entries"][1][
"ttl_seconds"];
157 $newValue = $this->
doSet( $key, $sum, $oldTTL ) ? $sum :
false;
162 wincache_unlock( $key );
167 public function incr( $key, $value = 1, $flags = 0 ) {
168 return $this->doIncr( $key, $value, $flags );
171 public function decr( $key, $value = 1, $flags = 0 ) {
172 return $this->doIncr( $key, -$value, $flags );
175 private function doIncr( $key, $value = 1, $flags = 0 ) {
177 if ( !wincache_lock( $key ) ) {
181 $n = $this->
doGet( $key );
183 $n = max( $n + (
int)$value, 0 );
184 $oldTTL = wincache_ucache_info(
false, $key )[
"ucache_entries"][1][
"ttl_seconds"];
185 $this->
doSet( $key, $n, $oldTTL );
190 wincache_unlock( $key );
unserialize( $serialized)
string $keyspace
Default keyspace; used by makeKey()
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.
isInteger( $value)
Check if a value is an integer.
Wrapper for WinCache object caching functions; identical interface to the APC wrapper.
doDelete( $key, $flags=0)
Delete an item.
doGet( $key, $flags=0, &$casToken=null)
Get an item.
doCas( $casToken, $key, $value, $exptime=0, $flags=0)
Set an item if the current CAS token matches the provided CAS token.
doAdd( $key, $value, $exptime=0, $flags=0)
Insert an item if it does not already exist.
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.
__construct(array $params=[])
doIncrWithInit( $key, $exptime, $step, $init, $flags)
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.