Jan 11th, 2012, 09:52 AM
Where can I put a caching object into the application scope on startup the app?
I'm using Spring 3 and I want to put a caching object using Ehcache, JCS, or something else, to the application scope when my application starts...
What module of Spring I must to use and how?
Do you know some tutorial about how to do this?
I need this feature of my application because every user from any session must can have eccess to this object.
Also, do you know some caching library implementation that can support the update of my caching objects in a defined time? Something like a scheduler that can update my caching object automaticaly? Or some way to do this using Quartz or Spring Batch?
I hope my questions are clear, or tell me if I need to explain more clearly my doubts.
Thanks in advance...
Jan 11th, 2012, 11:42 AM
By default all Spring Beans are configured to be Singleton scope, and the Spring Container is almost always application scope, I say almost, just because it depends on when and where you create your App context. So by default if you define your bean for your cache, then it is already how you need it.
For time based invalidation of cache's. That is based on the cache implementation you use and its configuration. I believe in your ehcache.xml for your cache region you can set a time based invalidation.
As far as pre-populating your cache, you can always use init-method in <bean> tag or if you have the code you can add @PostConstruct and <context:annotation-config> to have a method run after the object has been instantiated.
Jan 11th, 2012, 12:44 PM
Thanks for your approaches...
So, if I use the invalitation approach, how can I re-populate the cache with the new contents of the objects automatically?
Jan 11th, 2012, 01:37 PM
That would be a caching product feature. I recommend checking out the ehcache documentation to see if they have that feature. Typically they have a refresh feature.
Jan 12th, 2012, 05:55 PM
Thanks for your replies... I'm testing the approaches...
Tags for this Thread