mireiawen / cache
PhpFastCache缓存后端的包装器
0.2.2
2019-10-06 23:41 UTC
Requires
- php: >=7.3.0
- ext-gettext: *
- phpfastcache/phpfastcache: ^7.1
This package is auto-updated.
Last update: 2024-09-22 15:37:33 UTC
README
PhpFastCache缓存后端的包装器,使用其PSR-16实现。此包装器支持一些更常见的驱动程序,并提供读取、写入、删除和检查后端键的方法。
- 类:
Cache
- 命名空间:
Mireiawen\Cache
要求
- 缓存后端
- PHP7
安装
您可以从GitHub仓库克隆或下载代码,或者使用composer:composer require mireiawen/cache
方法
__construct
Cache::__construct(string $driver, array $config = [])
设置缓存后端驱动程序
参数
- string
$driver
- 要使用的缓存后端驱动程序,目前支持以下几种- files
- memcache
- memcached
- redis
- predis
- array
$config
- 后端特定的配置选项files
:path
- 存储缓存数据的文件系统路径
memcache
,memcached
host
- 要连接的主机名,默认为localhost
port
- 要连接的端口,默认为11211
redis
,predis
host
- 要连接的主机名,默认为localhost
port
- 要连接的端口,默认为6379
password
- 连接时使用的密码,默认为NULL
database
- 要使用的数据库,默认为NULL
抛出的异常
PhpfastcacheDriverCheckException
- 在驱动程序错误时
PhpfastcacheLogicException
- 在PhpFastCache逻辑错误时
\Exception
- 在配置错误的情况下
可用
Cache::Available(string $id)
检查键是否存在于缓存后端
参数
- string
$id
- 要检查的缓存ID
返回值
- bool - 如果$id已缓存则为TRUE,否则为FALSE
抛出的异常
PhpfastcacheSimpleCacheException
- 在缓存错误时
无效化
Cache::Invalidate(string $id)
使缓存后端的键无效或删除
参数
- string
$id
- 要无效化的缓存ID
抛出的异常
PhpfastcacheSimpleCacheException
- 在缓存错误时
写入
Cache::Write(string $id, mixed $value, int $ttl)
将值存储到缓存后端
参数
- string
$id
- 要存储的缓存ID - mixed
$value
- 要存储到缓存的值 - int
$ttl
- 缓存项的生存时间
抛出的异常
PhpfastcacheSimpleCacheException
- 在缓存错误时
读取
Cache::Read(string $id)
从缓存后端检索存储的值
参数
- string
$id
- 要读取的缓存ID
返回值
- mixed - 键的存储值
抛出的异常
PhpfastcacheSimpleCacheException
- 在缓存错误时