Wikibase
MediaWiki Wikibase extension
Wikibase\Lib\SimpleCacheWithBagOStuff Class Reference
+ Inheritance diagram for Wikibase\Lib\SimpleCacheWithBagOStuff:
+ Collaboration diagram for Wikibase\Lib\SimpleCacheWithBagOStuff:

Public Member Functions

 __construct (BagOStuff $inner, string $prefix, string $secret)
 
 get ( $key, $default=null)
 Fetches a value from the cache. More...
 
 set ( $key, $value, $ttl=null)
 Persists data in the cache, uniquely referenced by a key with an optional expiration TTL time. More...
 
 delete ( $key)
 Delete an item from the cache by its unique key. More...
 
 clear ()
 Wipes clean the entire cache's keys. More...
 
 getMultiple ( $keys, $default=null)
 Obtains multiple cache items by their unique keys. More...
 
 setMultiple ( $values, $ttl=null)
 Persists a set of key => value pairs in the cache, with an optional TTL. More...
 
 deleteMultiple ( $keys)
 Deletes multiple cache items in a single operation. More...
 
 has ( $key)
 Determines whether an item is present in the cache. More...
 

Private Member Functions

 assertKeysAreValidAllowIntegers ( $keys)
 
 assertKeysAreValid ( $keys)
 
 assertKeyIsValid ( $key)
 
 toArray ( $var)
 
 toAssociativeArray ( $var)
 
 isIterable ( $var)
 
 normalizeTtl ( $ttl)
 
 serialize ( $value)
 
 unserialize ( $string, $default, array $loggingContext)
 

Private Attributes

const INVALID_KEY_REGEX = '/[\{\}\‍(\‍)\/\\\\@:]/'
 
 $inner
 
 $prefix
 
 $secret
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

Wikibase\Lib\SimpleCacheWithBagOStuff::__construct ( BagOStuff  $inner,
string  $prefix,
string  $secret 
)
Parameters
BagOStuff$inner
string$prefixWhile setting and getting all keys will be prefixed with this string
string$secretWill be used to create a signature for stored values
Exceptions

Member Function Documentation

◆ assertKeyIsValid()

Wikibase\Lib\SimpleCacheWithBagOStuff::assertKeyIsValid (   $key)
private

◆ assertKeysAreValid()

Wikibase\Lib\SimpleCacheWithBagOStuff::assertKeysAreValid (   $keys)
private

◆ assertKeysAreValidAllowIntegers()

Wikibase\Lib\SimpleCacheWithBagOStuff::assertKeysAreValidAllowIntegers (   $keys)
private

◆ clear()

Wikibase\Lib\SimpleCacheWithBagOStuff::clear ( )

Wipes clean the entire cache's keys.

Returns
bool True on success and false on failure.

◆ delete()

Wikibase\Lib\SimpleCacheWithBagOStuff::delete (   $key)

Delete an item from the cache by its unique key.

Parameters
string$keyThe unique cache key of the item to delete.
Returns
bool True if the item was successfully removed. False if there was an error.
Exceptions
CacheInvalidArgumentExceptionMUST be thrown if the $key string is not a legal value.

◆ deleteMultiple()

Wikibase\Lib\SimpleCacheWithBagOStuff::deleteMultiple (   $keys)

Deletes multiple cache items in a single operation.

Parameters
iterable$keysA list of string-based keys to be deleted.
Returns
bool True if the items were successfully removed. False if there was an error.
Exceptions
CacheInvalidArgumentExceptionMUST be thrown if $keys is neither an array nor a Traversable, or if any of the $keys are not a legal value.

◆ get()

Wikibase\Lib\SimpleCacheWithBagOStuff::get (   $key,
  $default = null 
)

Fetches a value from the cache.

Parameters
string$keyThe unique key of this item in the cache.
mixed$defaultDefault value to return if the key does not exist.
Returns
mixed The value of the item from the cache, or $default in case of cache miss.
Exceptions
CacheInvalidArgumentExceptionMUST be thrown if the $key string is not a legal value.

◆ getMultiple()

Wikibase\Lib\SimpleCacheWithBagOStuff::getMultiple (   $keys,
  $default = null 
)

Obtains multiple cache items by their unique keys.

Parameters
iterable$keysA list of keys that can obtained in a single operation.
mixed$defaultDefault value to return for keys that do not exist.
Returns
iterable A list of key => value pairs. Cache keys that do not exist or are stale will have $default as value.
Exceptions
CacheInvalidArgumentExceptionMUST be thrown if $keys is neither an array nor a Traversable, or if any of the $keys are not a legal value.

◆ has()

Wikibase\Lib\SimpleCacheWithBagOStuff::has (   $key)

Determines whether an item is present in the cache.

NOTE: It is recommended that has() is only to be used for cache warming type purposes and not to be used within your live applications operations for get/set, as this method is subject to a race condition where your has() will return true and immediately after, another script can remove it making the state of your app out of date.

Parameters
string$keyThe cache item key.
Returns
bool
Exceptions
CacheInvalidArgumentExceptionMUST be thrown if the $key string is not a legal value.

◆ isIterable()

Wikibase\Lib\SimpleCacheWithBagOStuff::isIterable (   $var)
private

◆ normalizeTtl()

Wikibase\Lib\SimpleCacheWithBagOStuff::normalizeTtl (   $ttl)
private
Parameters
null | int | DateInterval$ttlThe TTL value of this item. If no value is sent and the driver supports TTL then the library may set a default value for it or let the driver take care of that.
Returns
int UNIX timestamp when the item should expire or \BagOStuff::TTL_INDEFINITE
Exceptions
CacheInvalidArgumentException

◆ serialize()

Wikibase\Lib\SimpleCacheWithBagOStuff::serialize (   $value)
private

◆ set()

Wikibase\Lib\SimpleCacheWithBagOStuff::set (   $key,
  $value,
  $ttl = null 
)

Persists data in the cache, uniquely referenced by a key with an optional expiration TTL time.

Parameters
string$keyThe key of the item to store.
mixed$valueThe value of the item to store, must be serializable.
null | int | DateInterval$ttlOptional. The TTL value of this item. If no value is sent and the driver supports TTL then the library may set a default value for it or let the driver take care of that.
Returns
bool True on success and false on failure.
Exceptions
CacheInvalidArgumentExceptionMUST be thrown if the $key string is not a legal value.

◆ setMultiple()

Wikibase\Lib\SimpleCacheWithBagOStuff::setMultiple (   $values,
  $ttl = null 
)

Persists a set of key => value pairs in the cache, with an optional TTL.

Parameters
iterable$valuesA list of key => value pairs for a multiple-set operation.
null | int | DateInterval$ttlOptional. The TTL value of this item. If no value is sent and the driver supports TTL then the library may set a default value for it or let the driver take care of that.
Returns
bool True on success and false on failure.
Exceptions
CacheInvalidArgumentExceptionMUST be thrown if $values is neither an array nor a Traversable, or if any of the $values are not a legal value.

◆ toArray()

Wikibase\Lib\SimpleCacheWithBagOStuff::toArray (   $var)
private
Parameters
mixed$varthe object to turn to array
Returns
array
Exceptions
CacheInvalidArgumentException

◆ toAssociativeArray()

Wikibase\Lib\SimpleCacheWithBagOStuff::toAssociativeArray (   $var)
private
Parameters
mixed$varthe object to turn to associative array
Returns
array
Exceptions
CacheInvalidArgumentException

◆ unserialize()

Wikibase\Lib\SimpleCacheWithBagOStuff::unserialize (   $string,
  $default,
array  $loggingContext 
)
private
Parameters
string$string
mixed$default
array$loggingContext
Returns
mixed
Exceptions

Member Data Documentation

◆ $inner

Wikibase\Lib\SimpleCacheWithBagOStuff::$inner
private

◆ $prefix

Wikibase\Lib\SimpleCacheWithBagOStuff::$prefix
private

◆ $secret

Wikibase\Lib\SimpleCacheWithBagOStuff::$secret
private

◆ INVALID_KEY_REGEX

const Wikibase\Lib\SimpleCacheWithBagOStuff::INVALID_KEY_REGEX = '/[\{\}\‍(\‍)\/\\\\@:]/'
private

The documentation for this class was generated from the following file: