spring – 缓存中的Ehcache Element生存期

以下列方式制作Spring服务的图像:

+--------+           +---------+             +---------+
|Backend | --------- | My      | ----------- | Clients |
|service |           | service |             |         |
+--------+           +---------+             +---------+

为了不向后端发出太多请求,我使用了Ehcache.
想象一下,我的服务是一个体育门户,我缓存结果,以便当客户端请求它们时,我返回缓存,如果没有缓存,我从后端获取信息,将其放入缓存,然后将其返回到客户.

现在,如果我设置了这些参数

long timeToLiveSeconds
long timeToIdleSeconds

并且客户端经常发出请求,timeToIdleSeconds不会过期,但timeToLiveSeconds无论如何都会过期,并且元素将从我放置的缓存中删除,对吧?

解决方法:

是的,你是对的.

例如:

timeToIdleSeconds = 30:如果在30秒内未请求缓存的对象,则expires =>最后访问时间计数

timeToLiveSeconds = 60:60秒后缓存的对象将过期 – 无论请求或请求的频率是多少=>创造时间很重要

从文档(旧版本1.4):

timeToIdleSeconds:
Sets the time to idle for an element before it expires.
i.e. The maximum amount of time between accesses before an element expires
Is only used if the element is not eternal.
Optional attribute. A value of 0 means that an Element can idle for infinity.
The default value is 0.

timeToLiveSeconds:
Sets the time to live for an element before it expires.
i.e. The maximum time between creation time and when an element expires.
Is only used if the element is not eternal.
Optional attribute. A value of 0 means that and Element can live for infinity.
The default value is 0.

上一篇:java – 如何刷新二级缓存?


下一篇:java – 找不到元素’ehcache’的声明