[英]How to Make guava cache value permanent
Is it possible, using Google Guava's Cache, to keep my cached value in the cache permanently? 是否可以使用Google Guava的缓存将我的缓存值永久保存在缓存中?
Below is how I build my cache: 以下是我建立快取的方式:
cache = CacheBuilder.newBuilder()
.expireAfterWrite(60, TimeUnit.MINUTES)
.maximumSize(100)
.build(....);
I want my cache to keep the value permanently (currently it's 60 minutes). 我希望我的缓存永久保留该值(当前为60分钟)。 Is there any method of doing so?
有什么办法吗?
Just remove expireAfterWrite
from builder (it's optional feature): 只需从构建器中删除
expireAfterWrite
(它是可选功能):
cache = CacheBuilder.newBuilder()
.maximumSize(100)
.build(....);
so that entries will be evicted only when maximumSize is reached. 这样,只有在达到maximumSize时,才会驱逐条目。
Guava's Cache is well documented but you should probably read Wiki page too. Guava的Cache有充分的文档记录,但您可能也应该阅读Wiki页面 。
PS If by "permanent" you meant "will be there after restart", Guava Cache isn't for you since it's in-memory cache. PS:如果“永久”是指“重启后将在那里”,那么Guava Cache不适合您,因为它是内存中的缓存。
Simply change the value in builder: 只需在builder中更改值:
cache = CacheBuilder.newBuilder()
.expireAfterWrite(Long.MAX_VALUE, TimeUnit.DAYS)
.maximumSize(Long.MAX_VALUE)
.build(....);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.