\Imi\CacheCacheManager

Summary

Methods
Properties
Constants
addName()
getNames()
clearPools()
getInstance()
get()
set()
delete()
clear()
getMultiple()
setMultiple()
deleteMultiple()
has()
No public properties found
No constants found
No protected methods found
$handlers
N/A
No private methods found
No private properties found
N/A

Properties

$handlers

$handlers : array<mixed,\Psr\SimpleCache\CacheInterface>

缓存处理器数组

Type

array<mixed,\Psr\SimpleCache\CacheInterface>

Methods

addName()

addName(string  $name, string  $handlerClass, array  $option = array()) : void

增加对象名称

Parameters

string $name
string $handlerClass
array $option

getNames()

getNames() : void

获取所有对象名称

clearPools()

clearPools() : void

清空池子

getInstance()

getInstance(string  $name) : \Psr\SimpleCache\CacheInterface

获取实例

Parameters

string $name

Returns

\Psr\SimpleCache\CacheInterface

get()

get(string  $name, string  $key, mixed  $default = null) : mixed

Fetches a value from the cache.

Parameters

string $name

对象名称

string $key

The unique key of this item in the cache.

mixed $default

Default value to return if the key does not exist.

Throws

\Psr\SimpleCache\InvalidArgumentException

MUST be thrown if the $key string is not a legal value.

Returns

mixed —

The value of the item from the cache, or $default in case of cache miss.

set()

set(string  $name, string  $key, mixed  $value, null|integer|\DateInterval  $ttl = null) : boolean

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

Parameters

string $name

对象名称

string $key

The key of the item to store.

mixed $value

The value of the item to store, must be serializable.

null|integer|\DateInterval $ttl

Optional. 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.

Throws

\Psr\SimpleCache\InvalidArgumentException

MUST be thrown if the $key string is not a legal value.

Returns

boolean —

True on success and false on failure.

delete()

delete(string  $name, string  $key) : boolean

Delete an item from the cache by its unique key.

Parameters

string $name

对象名称

string $key

The unique cache key of the item to delete.

Throws

\Psr\SimpleCache\InvalidArgumentException

MUST be thrown if the $key string is not a legal value.

Returns

boolean —

True if the item was successfully removed. False if there was an error.

clear()

clear(string  $name) : boolean

Wipes clean the entire cache's keys.

Parameters

string $name

对象名称

Returns

boolean —

True on success and false on failure.

getMultiple()

getMultiple(string  $name, \Imi\Cache\iterable  $keys, mixed  $default = null) : \Imi\Cache\iterable

Obtains multiple cache items by their unique keys.

Parameters

string $name

对象名称

\Imi\Cache\iterable $keys

A list of keys that can obtained in a single operation.

mixed $default

Default value to return for keys that do not exist.

Throws

\Psr\SimpleCache\InvalidArgumentException

MUST be thrown if $keys is neither an array nor a Traversable, or if any of the $keys are not a legal value.

Returns

\Imi\Cache\iterable —

A list of key => value pairs. Cache keys that do not exist or are stale will have $default as value.

setMultiple()

setMultiple(string  $name, \Imi\Cache\iterable  $values, null|integer|\DateInterval  $ttl = null) : boolean

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

Parameters

string $name

对象名称

\Imi\Cache\iterable $values

A list of key => value pairs for a multiple-set operation.

null|integer|\DateInterval $ttl

Optional. 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.

Throws

\Psr\SimpleCache\InvalidArgumentException

MUST be thrown if $values is neither an array nor a Traversable, or if any of the $values are not a legal value.

Returns

boolean —

True on success and false on failure.

deleteMultiple()

deleteMultiple(string  $name, \Imi\Cache\iterable  $keys) : boolean

Deletes multiple cache items in a single operation.

Parameters

string $name

对象名称

\Imi\Cache\iterable $keys

A list of string-based keys to be deleted.

Throws

\Psr\SimpleCache\InvalidArgumentException

MUST be thrown if $keys is neither an array nor a Traversable, or if any of the $keys are not a legal value.

Returns

boolean —

True if the items were successfully removed. False if there was an error.

has()

has(string  $name, string  $key) : boolean

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 $name

对象名称

string $key

The cache item key.

Throws

\Psr\SimpleCache\InvalidArgumentException

MUST be thrown if the $key string is not a legal value.

Returns

boolean