Skip to main content

Persistence Caching

Posted by jhook on January 3, 2007 at 9:54 PM PST

Working with Hibernate and attempting to wrap caching services elsewhere in one of our applications, I'm concerned with the way these caching frameworks handle expiration.

If you have many different types of domain artifacts that you want to cache with a given lifespan, how come all of these caching frameworks (EHCache, OSCache, etc) don't automatically clean up the memory? It becomes a game of roulette in trying to optimize the most memory usage vs. potential usage for any given time of day.

This becomes a greater issue when we get into SOA where we've previously been able to sneak away with scoping information in the session, knowing well that it will be cleaned up after a certain period of use. With stateless service tiers, the caches are based on some interval-- but EHCache/OSCache don't guarantee object expiration when the objects aren't needed anymore.

It seems just silly that these caches will retain reference to Objects needed 2 days ago, only to tell me they are no good when/if someone wants them again.

Am I wrong in this expectation? I would the execution would go something like:

public void store(String key, Object value, long time) {
    this.concurrentMap.put(new TempKey(key, System.currentTimeMillis() + time), value);

protected final Thread queueThread = new Thread(new Runnable() {
    public void run() {
      try {
          // clean up expired keys
      } catch (Exception e) { ... }
Related Topics >>