• Bug
  • Status: Closed
  • 2 Major
  • Resolution: Fixed
  • ehcache-core
  • cdennis
  • Reporter: edalquis
  • June 11, 2010
  • 0
  • Watchers: 2
  • July 27, 2012
  • June 14, 2010


In a unit test for my project we use a CacheUsageListener to verify actions on the cache. Upgrading from ehcache-core 2.0.1 to 2.1.0 causes the test to fail but it appears the culprit is actually ehcache not calling registered listeners.

Using the following test code:

final Ehcache ehcache = cacheManager.getEhcache(“triggersRemoveCountingCache”); final CacheUsageListener loggingListener = (CacheUsageListener)Proxy.newProxyInstance(this.getClass().getClassLoader(), new Class[] {CacheUsageListener.class}, new InvocationHandler() { public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { System.out.println(“Called: “ + method.getName());

    return null;
} \}); ehcache.registerCacheUsageListener(loggingListener);

Actions after this point using ehcache-core 2.0.1 print out all operations as expected. Using 2.1.0 nothing is ever printed, no listener method is ever invoked.

The cache configuration is:


Fiona OShea 2010-06-11

Chris did we break something? Or is this something we know about?

Gary Keim 2010-06-11

In 2.1.0 statistics are disabled by default and CacheUsageListener’s depend on the stats:

Gary Keim 2010-06-12

I didn’t mean to come off as such an authority on the subject, as I was just relaying the way I see things from a code point-of-view.

Maybe there’s a feature/enhancement here.

Eric Dalquist 2010-06-12

Thanks for the info. I guess the only concern I have with the change is it will silently break existing usages of Ehcache. I would have voted for API stability in adding the statistics attribute and had it default to true with the ability to disable on a per cache basis.

Eric Dalquist 2010-06-13

Perhaps a WARN level log message could be issued whenever registerCacheUsageListener is called if the statistics attribute is not set on the element. That shouldn't really pollute a log file but then at least implementers will be aware of the API change.

Chris Dennis 2010-06-14

The current behavior in terms of not working when statistics is disabled does seem to make sense given that CacheUsageListeners are javadoc’ed as:

* Interface for listeners to any change in usage statistics of an Ehcache.

If the statistics are disabled they obviously don’t change, and hence there are no events. Originally statistics did default to true, with the option of disabling on a per-cache basis, however the decision to move to disabling it by default was made to enhance performance for the majority of users.

A WARN level log message does however seem like a good idea, so I will make the necessary change in ehcache-core.

Eric Dalquist 2010-06-14

I agree, the behavior makes sense. It was just the change between 2.0 and 2.1 that caused the problem. If you’re not on the lookout in the changelog for that specific default switch your listeners break with no real explanation as to why.

Thanks for the time and explanations!