用AI赚第一桶💰低成本搭建一套AI赚钱工具,源码可二开。 广告
## 缓存 缓存组件通常用于缓存某些信息,避免过多的数据库查询或大量计算,基于 [PSR-6](https://www.php-fig.org/psr/psr-6/) 标准实现。 ## 组件 使用 [composer]([https://www.phpcomposer.com/](https://www.phpcomposer.com/)) 安装: ~~~ composer require mix/cache ~~~ ## 依赖注入配置 - [manifest/beans/cache.php](https://github.com/mix-php/mix-skeleton/blob/master/manifest/beans/cache.php) 缓存组件支持多种处理器: - Mix\Cache\Handler\RedisHandler::class:使用 redis 保存缓存数据 - Mix\Cache\Handler\FilesystemHandler::class:使用本地文件保存缓存数据 - Mix\Cache\Handler\ArrayHandler::class:使用内存数组保存缓存数据 框架默认是配置的 FileHandler::class,只需修改 Mix\Cache\Cache::class 的 handler 属性内 ref 的 class 即可切换为 RedisHandler::class。 ## 获取实例 通过依赖配置获取实例: ~~~ /** @var \Mix\Cache\Cache $cache */ $cache = context()->get('cache'); ~~~ ## PSR 定义方法 | 方法 | 描述 | | --- | --- | | get($key, $default = null): mixed | 获取缓存 | | set($key, $value, $ttl = null) : bool | 设置缓存 | | delete($key) : bool | 删除缓存 | | clear() : bool | 清除缓存 | | getMultiple($keys, $default = null) : array | 批量获取 | | setMultiple($values, $ttl = null) : bool | 批量设置 | | deleteMultiple($keys) : bool | 批量删除 | | has($key) : bool | 判断缓存是否存在 |