composer require deathkel/easy-cache
php
这个包会自动缓存使用了该 'trait' 的 'class' 的protect方法git
默认缓存时间是60分钟,你能够添加一个static
变量 $expire
到你的 'fucntion' 中来单独设置该 'function' 的缓存时间github
public class test(){ use EasyCacheTrait; public function DontWantToBeCache(){ // public function 不会被缓存 //..... } protected function WantToBeCache(){ // protected function 会被自动缓存 static $expire = 60; //默认缓存时间 } }
你能够添加 'skipCache = 1' 你的http查询参数来跳过缓存直接执行方法缓存
你还能够添加 'forgetCache = 1' 来忘记你的缓存并从新缓存composer