32 $params[
'segmentationSize'] = $params[
'segmentationSize'] ?? INF;
33 parent::__construct( $params );
35 if ( PHP_SAPI ===
'cli' ) {
44 protected function doGet( $key, $flags = 0, &$casToken =
null ) {
45 $getToken = ( $casToken === self::PASS_BY_REF );
48 $blob = wincache_ucache_get( $key );
49 if ( !is_string(
$blob ) && !is_int(
$blob ) ) {
54 if ( $getToken && $value !==
false ) {
55 $casToken = (string)
$blob;
61 protected function doCas( $casToken, $key, $value, $exptime = 0, $flags = 0 ) {
62 if ( !wincache_lock( $key ) ) {
66 $curCasToken = self::PASS_BY_REF;
67 $this->
doGet( $key, self::READ_LATEST, $curCasToken );
68 if ( $casToken === $curCasToken ) {
69 $success = $this->
set( $key, $value, $exptime, $flags );
72 __METHOD__ .
' failed due to race condition for {key}.',
79 wincache_unlock( $key );
84 protected function doSet( $key, $value, $exptime = 0, $flags = 0 ) {
86 $result = wincache_ucache_set( $key, $this->
getSerialized( $value, $key ), $ttl );
91 return ( $result === [] || $result ===
true );
94 protected function doAdd( $key, $value, $exptime = 0, $flags = 0 ) {
95 if ( wincache_ucache_exists( $key ) ) {
100 $result = wincache_ucache_add( $key, $this->
getSerialized( $value, $key ), $ttl );
105 return ( $result === [] || $result ===
true );
109 wincache_ucache_delete( $key );
120 $charsLeft = 125 - strlen(
$keyspace ) - count( $components );
122 $components = array_map(
123 static function ( $component ) use ( &$charsLeft ) {
125 if ( $charsLeft > 33 && strlen( $component ) > $charsLeft ) {
126 $component =
'#' . md5( $component );
129 $charsLeft -= strlen( $component );
135 if ( $charsLeft < 0 ) {
136 return $keyspace .
':BagOStuff-long-key:##' . md5( implode(
':', $components ) );
139 return $keyspace .
':' . implode(
':', $components );
142 public function incr( $key, $value = 1, $flags = 0 ) {
143 if ( !wincache_lock( $key ) ) {
147 $n = $this->
doGet( $key );
149 $n = max( $n + (
int)$value, 0 );
150 $oldTTL = wincache_ucache_info(
false, $key )[
"ucache_entries"][1][
"ttl_seconds"];
151 $this->
set( $key, $n, $oldTTL );
156 wincache_unlock( $key );
161 public function decr( $key, $value = 1, $flags = 0 ) {
162 return $this->
incr( $key, -$value, $flags );
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)
doCas( $casToken, $key, $value, $exptime=0, $flags=0)
Check and set an item.
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=[])
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.