企业🤖AI Agent构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
# CatCache SD自带的可落地的高速缓存 ## 配置 在CatCache.php配置文件中启用CatCache ``` /** * 是否启动CatCache */ $config['catCache']['enable'] = true; //自动存盘时间 $config['catCache']['auto_save_time'] = 1000; //落地文件夹 $config['catCache']['save_dir'] = BIN_DIR . '/cache/'; //RPC代理 $config['catCache']['rpcProxyClass'] = CatCacheRpcProxy::class; //分割符 $config['catCache']['delimiter'] = "."; ``` * auto_save_time 自动存盘时间,单位是秒 * save_dir 存盘路径 * rpcProxyClass RPC代理,高级用法 * delimiter 路径分隔符 CatCache拥有2种存盘模式,一种是全盘落地通过auto_save_time参数控制,一旦到达时间就会执行存盘操作。另外是日志模式,记录用户的增加删除操作,2种模式会尽量保证数据不会丢失。 delimiter是分隔符 ``` CatCacheRpcProxy::getRpc()['test.a'] ``` 这样其实是获取test数组中a的值,通过更改delimiter可以变化分隔符,不影响数据。 auto_save_time要好好设计,不能太久,会导致log日志过多,太短影响效率。 ## 使用 ``` public function http_testSC1() { $result = yield CatCacheRpcProxy::getRpc()->offsetExists('test.bc'); $this->http_output->end($result, false); } public function http_testSC2() { unset(CatCacheRpcProxy::getRpc()['test.a']); $this->http_output->end(1, false); } public function http_testSC3() { CatCacheRpcProxy::getRpc()['test.a'] = ['a' => 'a', 'b' => [1, 2, 3]]; $this->http_output->end(1, false); } public function http_testSC4() { $result = yield CatCacheRpcProxy::getRpc()['test']; $this->http_output->end($result, false); } public function http_testSC5() { $result = yield CatCacheRpcProxy::getRpc()->getAll(); $this->http_output->end($result, false); } ```