ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、视频、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
## 请求缓存 RequestCacheInterceptor 是一个内置的拦截器会对请求进行拦截,会将控制器的缓存结果进行缓存,在下次获取时可以直接返回 使用: ~~~ class AppInit implements Init { /** * @var Application */ private $application; public function __construct(Application $application) { $this->application = $application; } public function appInit(AutoFindHandlerMapping $autoMapping, Router $router) { $interceptor = Ioc::get(RequestCacheInterceptor::class); $interceptor->cache('/test/test', 60); $interceptor->cache('/test/test1', 60); $interceptor->refreshGet('refresh'); $interceptor->refreshHeader('rap-refresh-request'); //添加拦截器 $this->application->addInterceptor(RequestCacheInterceptor::class,10); } ~~~ ### cache 添加需要缓存的路径,和缓存时间,路径不能包含请求参数,系统内部会对所有 get 参数进行排序后和路径一起生成 缓存的key ### refreshGet 如果get参数中包含会强制刷新缓存 ### refreshHeader 如果请求头中包含会强制刷新缓存