DFL
DFL

Reputation: 173

Spring SimpleCacheManager update strategy?

I'm adding caching to a small but frequently used database call in my application. The table it's hitting will update very infrequently, so it's a great candidate for caching. I've implemented it with org.springframework.cache.support.SimpleCacheManager, and I'd like to know more about its update strategy, but I can't seem to find anything about it.

Mostly, I'd like to know if it periodically evicts the cache, and if it does, what kind of schedule does it do it on? I'm almost certain that the default caching will work, but I want to make sure.

Upvotes: 1

Views: 1238

Answers (1)

Vasu
Vasu

Reputation: 22442

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.

Please find the below sample ehcache configuration for spring.

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

Also, refer the below spring cache documentation:

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

You can find a simple spring-ehcache example below:

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

Upvotes: 1

Related Questions