gpt4 book ai didi

java - Spring SimpleCacheManager更新策略?

转载 作者:行者123 更新时间:2023-12-01 09:40:54 24 4
gpt4 key购买 nike

我正在将缓存添加到应用程序中一个小型但经常使用的数据库调用中。它所访问的表很少更新,因此它是缓存的绝佳候选者。我已经用 org.springframework.cache.support.SimpleCacheManager 实现了它,我想了解更多有关其更新策略的信息,但我似乎找不到任何有关它的信息。

大多数情况下,我想知道它是否定期清除缓存,如果是,它是按照什么样的时间表执行的?我几乎可以肯定默认缓存会起作用,但我想确定一下。

最佳答案

The properties you have to know are "timeToIdleSeconds" and "timeToLiveSeconds" (in ehcache caching framework) which will decide how long the cache objects are valid for. Once the cache data becomes invalid, the data will be fetched again from database again and kept into cache.

请找到下面的 spring ehcache 配置示例。

<cache name="myProjectCache" 
maxEntriesLocalHeap="10000"
memoryStoreEvictionPolicy="LFU"
timeToIdleSeconds="300" timeToLiveSeconds="600">
</cache>

另外,请参阅下面的 spring 缓存文档:

http://docs.spring.io/spring/docs/current/spring-framework-reference/html/cache.html

您可以在下面找到一个简单的 spring-ehcache 示例:

http://www.mkyong.com/spring/spring-caching-and-ehcache-example/

关于java - Spring SimpleCacheManager更新策略?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38462296/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com