分享一个 Trait 来易用 Laravel 的缓存

求星求关注 https://github.com/deathkel/easy-cache

安装

composer require deathkel/easy-cachephp

使用

  • 这个包会自动缓存使用了该 '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; //默认缓存时间
    }
}

在Laravel的bug模式下

  • 你能够添加 'skipCache = 1' 你的http查询参数来跳过缓存直接执行方法缓存

  • 你还能够添加 'forgetCache = 1' 来忘记你的缓存并从新缓存composer

相关文章
相关标签/搜索