How do I set an cache time for objects in OSCache using spring-modules?

2.2k Views Asked by At

I have an application in need of some caching, and for some of the semi-static data, I want them to stay in the cache a maximum amount of time (for instance 10 minutes) before being refreshed. My system merely retrieves data, never updates it, so I have no idea of when to flush the cache using the property. In the OSCache docs, such an expiry time can be set both using the programmatic API and the configuration for the taglib, but the spring-modules documentation is silent on the matter.

Does anyone know if/how this can be done?

2

There are 2 best solutions below

1
On BEST ANSWER

I figured it out. The answer is hidden in ehcache's own configuration file. By setting the property "timeToLiveSeconds" to for instance "600", the element in the cache will expire after ten minutes.

0
On

take a look at https://springmodules.dev.java.net/docs/reference/0.8/html/cache.html

3.5.2. Caching Models they provide an example with org.springmodules.cache.provider.jcs.JcsCachingModel

try playing around with org.springmodules.cache.provider.oscache.OsCacheCachingModel

the source code from http://www.koders.com/java/fidB7163A5070666F5BD98F43D4324011D1A969ABD3.aspx?s=mcall%3Astring gives me the properties

private String cronExpression;

private String[] groups;

private Integer refreshPeriod;

so you need to set the "refreshPeriod" property