繁体   English   中英

使用Redis在Laravel中缓存

[英]Cache in Laravel using Redis

我在laravel中构建应用程序,在其中我使用Redis进行缓存。 成功存储在缓存中,但问题是,我在一个浏览器中运行应用程序,并成功登录并存储了缓存,现在在另一个浏览器中它将自动登录。

我使用代码存储和加载缓存

if(Cache::has('mykey'))
{
    return Cache::get('mykey');
}
else
{
    // Do some operation and store it in cache
    Cache::put('mykey',content,10);
    // and then return
}

请告诉我出什么问题了...预先感谢

试试下面的代码:

// Check cache first
$catchPage = Cache::get('mykey');
if ($catchPage != null) {
    return $catchPage;
}
else {
    Cache::tags('tag_name')->put('mykey',$content,10);
    // and then return
}

这里参考。

根据laravel 5.3 Docs
您可以通过store方法访问各种缓存存储。

传递给store方法的密钥应对应于缓存配置文件中store配置数组中列出的存储之一:

$value = Cache::store('file')->get('foo');

Cache::store('redis')->put('bar', 'baz', 10);

如果需要从缓存中检索项目然后删除该项目,则可以使用pull方法。 get方法类似,如果该项目在缓存中不存在,则将返回null

$value = Cache::pull('key');

如果缓存中不存在该项目,则add方法只会将其添加到缓存中。 如果该项目实际上已添加到缓存,则该方法将返回true 否则,该方法将返回 false:

Cache::add('key', 'value', $minutes);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM