简易缓存

遵循 PSR16 规范,使用静态方法调用
属性
命名空间 fize\cache
类名 Cache
方法:
方法名 说明
__construct() 常规调用请先初始化
getInstance() 取得实例
get() 获取一个缓存
set() 设置一个缓存
delete() 删除一个缓存
clear() 清空所有缓存
getMultiple() 获取多个缓存
setMultiple() 设置多个缓存
deleteMultiple() 删除多个缓存
has() 判断缓存是否存在

方法

__construct()

常规调用请先初始化

public function __construct (
    string $handler,
    array $config = []
)
参数:
名称 说明
handler 使用的实际接口名称
config 配置项

getInstance()

取得实例

public static function getInstance (
    string $handler,
    array $config = []
) : \fize\cache\CacheInterface
参数:
名称 说明
handler 使用的实际接口名称
config 配置

get()

获取一个缓存

public static function get (
    string $key,
    mixed $default = null
) : mixed
参数:
名称 说明
key 键名
default 默认值

set()

设置一个缓存

public static function set (
    string $key,
    mixed $value,
    \DateInterval|int|null $ttl = null
) : bool
参数:
名称 说明
key 键名
value
ttl 以秒为单位的过期时长

delete()

删除一个缓存

public static function delete (
    string $key
) : bool
参数:
名称 说明
key 键名

clear()

清空所有缓存

public static function clear () : bool

getMultiple()

获取多个缓存

public static function getMultiple (
    iterable $keys,
    mixed $default = null
) : iterable
参数:
名称 说明
keys 键名数组
default 默认值

setMultiple()

设置多个缓存

public static function setMultiple (
    iterable $values,
    \DateInterval|int|null $ttl = null
) : bool
参数:
名称 说明
values [键名=>值]数组
ttl 以秒为单位的过期时长

deleteMultiple()

删除多个缓存

public static function deleteMultiple (
    iterable $keys
) : bool
参数:
名称 说明
keys 键名数组

has()

判断缓存是否存在

public static function has (
    string $key
) : bool
参数:
名称 说明
key 键名