I'm looking for an in-memory cache with the following behaviour.
- On the first access or after initialization it read's all data to be cached at once. E.g. all rows of a table.
- After one hour the complete cache is cleared and all data is read again at once.
- The cache could be cleared on demand.
I know how to implement such a cache, but does anybody know an existing library, which provides a cache like this.
This is my idea about the interface. There are elements for the cache
Element element = new Element(Object key, Object objectToCache);
A loader provides all elements
Collection<Element> elements = myLoader.getElements();
In the end there is the cache
public Cache {
public Cache(CacheLoader loader, int timeToReload) {
...
}
public Object getValueForKey(Object key {
...
}
...
}
A solution would be to have a cache with a single entry, which is a HashMap of the real entries. With this solution I can use existing caches like Ehcache or Guava Caches.
But nevertheless I'm looking for existing code, before I start writing a own library.