简易缓存接口¶
属性 | 值 |
---|---|
命名空间 | fize\cache |
类名 | CacheInterface |
实现接口 | Psr\SimpleCache\CacheInterface |
方法: |
---|
方法名 | 说明 |
---|---|
__construct() | 构造函数 |
get() | Fetches a value from the cache. |
set() | Persists data in the cache, uniquely referenced by a key with an optional expiration TTL time. |
delete() | Delete an item from the cache by its unique key. |
clear() | Wipes clean the entire cache’s keys. |
getMultiple() | Obtains multiple cache items by their unique keys. |
setMultiple() | Persists a set of key => value pairs in the cache, with an optional TTL. |
deleteMultiple() | Deletes multiple cache items in a single operation. |
has() | Determines whether an item is present in the cache. |
方法¶
get()¶
Fetches a value from the cache.
abstract public function get (
string $key,
mixed $default = null
) : mixed
参数: |
|
||||||
---|---|---|---|---|---|---|---|
返回值: | The value of the item from the cache, or $default in case of cache miss. |
set()¶
Persists data in the cache, uniquely referenced by a key with an optional expiration TTL time.
abstract public function set (
string $key,
mixed $value,
null|int|\DateInterval $ttl = null
) : bool
参数: |
|value |The value of the item to store, must be serializable. | +——-+—————————————————————————————————————————————————————————+ |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. | +——-+—————————————————————————————————————————————————————————+ |
||||||
---|---|---|---|---|---|---|---|
返回值: | True on success and false on failure. |
delete()¶
Delete an item from the cache by its unique key.
abstract public function delete (
string $key
) : bool
参数: |
|
||||
---|---|---|---|---|---|
返回值: | True if the item was successfully removed. False if there was an error. |
clear()¶
Wipes clean the entire cache’s keys.
abstract public function clear () : bool
返回值: | True on success and false on failure. |
---|
getMultiple()¶
Obtains multiple cache items by their unique keys.
abstract public function getMultiple (
iterable $keys,
mixed $default = null
) : iterable
参数: |
|
||||||
---|---|---|---|---|---|---|---|
返回值: | A list of key => value pairs. Cache keys that do not exist or are stale will have $default as value. |
setMultiple()¶
Persists a set of key => value pairs in the cache, with an optional TTL.
abstract public function setMultiple (
iterable $values,
null|int|\DateInterval $ttl = null
) : bool
参数: |
|values |A list of key => value pairs for a multiple-set operation. | +——-+—————————————————————————————————————————————————————————+ |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. | +——-+—————————————————————————————————————————————————————————+ |
||||
---|---|---|---|---|---|
返回值: | True on success and false on failure. |
deleteMultiple()¶
Deletes multiple cache items in a single operation.
abstract public function deleteMultiple (
iterable $keys
) : bool
参数: |
|
||||
---|---|---|---|---|---|
返回值: | True if the items were successfully removed. False if there was an error. |
has()¶
Determines whether an item is present in the cache.
abstract public function has (
string $key
) : bool
参数: |
|
---|
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.