我可以为@Cacheable设置TTL吗? [英] Can I set a TTL for @Cacheable
问题描述
我正在尝试对Spring 3.1的 @Cacheable
注释支持,并想知道是否有任何方法可以通过设置TTL在一段时间后清除缓存数据?
现在我可以看到我需要通过使用 @CacheEvict
来清除它,并将其与一起使用@预定的
我可以自己做一个TTL实现,但对于这么简单的任务来说似乎有点多了?
I am trying out the @Cacheable
annotation support for Spring 3.1 and wondering if there is any way to make the cached data clear out after a time by setting a TTL?
Right now from what I can see I need to clear it out myself by using the @CacheEvict
, and by using that together with @Scheduled
I can make a TTL implementation myself but it seems a bit much for such a simple task?
推荐答案
如何设置TTL / TTI /驱逐政策/ XXX功能?
How can I set the TTL/TTI/Eviction policy/XXX feature?
直接通过缓存提供程序。缓存抽象是......
好,抽象不是缓存实现
Directly through your cache provider. The cache abstraction is... well, an abstraction not a cache implementation
所以,如果你使用EHCache,请使用EHCache配置TTL的配置。
So, if you use EHCache, use EHCache's configuration to configure the TTL.
你也可以使用Guava的 CacheBuilder 构建缓存,并将此缓存的ConcurrentMap视图传递给 setStore ConcurrentMapCacheFactoryBean的方法。
You could also use Guava's CacheBuilder to build a cache, and pass this cache's ConcurrentMap view to the setStore method of the ConcurrentMapCacheFactoryBean.
这篇关于我可以为@Cacheable设置TTL吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!