• New Feature
  • Status: Open
  • 2 Major
  • Resolution:
  • ehcache-core
  • Reporter: mindas
  • November 02, 2011
  • 0
  • Watchers: 3
  • May 28, 2013

Description

This is a spin-off from http://stackoverflow.com/q/7953980/7345

I am trying to write a custom logger for Ehcache, which would allow to trace the following:

  • when an element is added to the cache - log it’s cache key, including expiry.
  • when an element is removed from the cache - log as above, also why it’s been evicted (if this ever occurs)
  • when a cache hit occurs (something is successfully loaded from the cache) - logging it’s cache key, expiry etc
  • when a stale hit occurs - logging why it was stale, cache key, expiry etc
  • when a cache flush occurs - logging what caused the flush, and what was flushed.

I could either do this by implementing n.s.e.e.CacheEventListener or n.s.e.s.LiveCacheStatisticsData, but the former doesn’t even provide hooks to cache GET methods (never mind the more detailed info, such as stale hit) whereas the latter doesn’t provide access to the cache key.

I don’t think adding more logging to the n.s.e.Cache itself would help as people have different needs and different opinions/frameworks on how things should be logged. Providing hooks would just serve all tastes.

Above said, would it be possible to add more hooks to the n.s.e.e.CacheEventListener?

Comments

Fiona OShea 2011-11-08

Hi Greg what do you think regarding this feature request.

gluck 2011-11-08

Ehcache is implementing JSR107 and is adding a get listener.

But for the types of things you list I think a combination of a Cache Decorator so that you can intercept calls to get, put etc, and listeners will get you most of the way there.