laravel - 永久缓存,包括服务器重启和 redis 到磁盘功能

标签 laravel caching redis

laravel 相关:

在 laravel 文档中我们写了这个 https://laravel.com/docs/5.4/cache

Storing Items Forever

The forever method may be used to store an item in the cache permanently. Since these items will not expire, they must be manually removed from the cache using the forget method: Cache::forever('key', 'value'); If you are using the Memcached driver, items that are stored "forever" may be removed when the cache reaches its size limit.

重启呢?内存缓存将被删除,那么“永远”呢?

所以永远并不意味着永远,但最终只会直到下一次重启/崩溃?

关于redis:

我听到很多人称赞“它可以存储到磁盘”

如果服务器崩溃了怎么办?缓存当前也存储在那里吗? redis 会自动处理吗?可能不是。所以我真的不明白它有什么好处。 “redis 可以存储到磁盘”是解决上述“永远”问题的方法吗?如果是这样,你能解释一下吗?

最佳答案

Cache::forever('key', 'value')
它意味着存储值(value),没有任何 ttl(生存时间)。但是当缓存大小达到其分配的大小时,之前存储的值将被删除。

Redis
如果你问redis。它根据配置将值存储到磁盘。如果服务器崩溃,如果您的磁盘文件没有损坏,您也可以通过重新启动它来找到旧数据。仅当 redis 空间大小已满或您已为值设置 ttl 时,才会删除来自 redis 的旧数据。

关于laravel - 永久缓存,包括服务器重启和 redis 到磁盘功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44276309/

相关文章:

laravel - laravel5中 `--table`和 `--create`选项之间的差异使:migration

java - 在 Play 2.5.x 中找不到类 play.api.cache.CacheApi 的构造函数

android - 我的图像缓存进程会泄漏内存吗?

objective-c - RestKit - fetchFromDataStore(缓存)问题

caching - Redis 加载 Lua 脚本并从文件缓存它(而不是 SCRIPT LOAD)

laravel - 测试 Laravel 时无法连接到 sqlite

php - 使用 Laravel 和 Pest 测试多维数组

java - Jedis(Redis)减速

spring-boot - @Cacheable 在 Controller 中工作,但不在服务内部工作

php - 如何修复 stripe-php 没有这样的 payment_method 错误