caching a database into an array which refreshes every 5 minutes
I need to cache a database into an array using Java, what is the best way to do this?
I need this array to refresh every 5 mi开发者_C百科nutes and I need to be able to query the array.
I'm looking to use two arrays and Some form of DAO DTO implementation.
Are there any set frameworks for this?
Some key points to make your life easier:
- Use the singleton pattern for your cached data serivce
- Use a scheduled executor to periodically refresh the data
- Make sure the refresh is atomic - consider using an AtomicReference to hold the data
you can use ehcache for this, you need to configure your DAO DTO implementation to cache its results & lookup results from the cache...
you can achieve the cache refresh by configuring the eviction time (time period for the cache to be cleared).
精彩评论