43 $params[
'segmentationSize'] = $params[
'segmentationSize'] ?? 917504;
44 parent::__construct( $params );
46 $this->routingPrefix = $params[
'routingPrefix'] ??
'';
65 $charsLeft = 205 - strlen(
$keyspace ) - count( $components );
67 foreach ( $components as &$component ) {
68 $component = strtr( $component,
' ',
'_' );
71 $component = preg_replace_callback(
72 '/[^\x21-\x22\x24\x26-\x39\x3b-\x7e]+/',
73 static function ( $m ) {
74 return rawurlencode( $m[0] );
80 if ( $charsLeft > 33 && strlen( $component ) > $charsLeft ) {
81 $component =
'#' . md5( $component );
84 $charsLeft -= strlen( $component );
87 if ( $charsLeft < 0 ) {
88 return $keyspace .
':BagOStuff-long-key:##' . md5( implode(
':', $components ) );
91 return $keyspace .
':' . implode(
':', $components );
103 if ( preg_match(
'/[^\x21-\x7e]+/', $key ) ) {
104 throw new Exception(
"Key contains invalid characters: $key" );
117 if ( $this->routingPrefix ===
'' ) {
121 if ( $key[0] ===
'/' ) {
122 throw new RuntimeException(
"Key '$key' already contains a route." );
125 return $this->routingPrefix . $key;
133 if ( $this->routingPrefix ===
'' ) {
137 $prefixLength = strlen( $this->routingPrefix );
138 if ( substr( $key, 0, $prefixLength ) === $this->routingPrefix ) {
139 return substr( $key, $prefixLength );
150 if ( $exptime < 0 ) {
159 $expiresAt = min( $exptime, self::TTL_MONTH );
161 $expiresAt = $exptime;
164 return (
int)$expiresAt;
168 if ( $flags & self::WRITE_BACKGROUND ) {
string $keyspace
Default keyspace; used by makeKey()
Storage medium specific cache for storing items (e.g.
isRelativeExpiration( $exptime)
Base class for memcached clients.
doIncrWithInit( $key, $exptime, $step, $init, $flags)
validateKeyEncoding( $key)
Ensure that a key is safe to use (contains no control characters and no characters above the ASCII ra...
__construct(array $params)
doIncrWithInitSync( $key, $exptime, $step, $init)
validateKeyAndPrependRoute( $key)
makeKeyInternal( $keyspace, $components)
Construct a cache key.
string $routingPrefix
Routing prefix appended to keys during operations.
doIncrWithInitAsync( $key, $exptime, $step, $init)