且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

具有不同会话生存期的Laravel

更新时间:2021-11-06 01:22:02

对于您的特殊情况,应改用缓存.我通常会这样做:

For your particular case you should use the cache instead. I generally do:

$value = Cache::remember('key', now()->addMinutes(5), function () { 
    /* get and return the value if it's not in the cache */ 
});

remember是一种便捷的方法,可以从缓存中获取值或运行回调,将结果放入缓存中并返回结果(这意味着下一个调用将直接到达缓存).

remember is a convenience method to either get the value from cache or run the callback, put the result in the cache and return the result (meaning the next call will just hit the cache).

更多信息可以在文档中的检索并删除;商店

More information can be found in the documentation under Retrieve & Store