美文网首页
laravel 中 Cache 的使用|2019-02-12

laravel 中 Cache 的使用|2019-02-12

作者: OSong | 来源:发表于2019-02-12 22:42 被阅读4次
use Illuminate\Support\Facades\Cache;

    public function cache1()
    {
        //put 写入缓存
        Cache::put('key1', 'val10', 10);
        //add() 添加缓存 成功返回 true 如果键存在返回 false
        $bool = Cache::add('key2', 'val2', 10);
        var_dump($bool);
        //forever 永久缓存, 没有过期时间
        Cache::forever('key3', 'val3');
        //使用 has 判断键是否存在
        if(Cache::has('key4')) {
            $val = Cache::get('key3');
            var_dump($val);
        } else {
            echo 'No';
        }
    }


  public function cache2()
    {
        //get() 取出缓存
        $val = Cache::get('key1');
        var_dump($val);
        //pull() 取出缓存,并从缓存中移除
        $val2 = Cache::pull('key2');
        var_dump($val2);
        //forget() 从缓存移除 成功返回 true 失败返回 false
        $bool = Cache::forget('key3');
        var_dump($bool);
    }

image.png

相关文章

网友评论

      本文标题:laravel 中 Cache 的使用|2019-02-12

      本文链接:https://www.haomeiwen.com/subject/izuleqtx.html