• Bug
  • Status: Closed
  • Resolution: Fixed
  • drb
  • Reporter: sourceforgetracker
  • September 21, 2009
  • 0
  • Watchers: 0
  • September 22, 2009
  • September 22, 2009



The problem is that I cannot create my caches from a class that is also a CacheManagerEventListener because the CacheManager.init method is called in the CacheManager contructor.

Ex. :

cacheManager = CacheManager.create(configFileName); // Too late to register for events, they were already sent! cacheManager.setCacheManagerEventListener(this);


a) Have 4 public static create methods to create the CacheManager singleton instance:

private void create(Configuration configuration) private void create(String configurationFileName) private void create(URL configurationURL) private void create(InputStream configurationInputStream)

b) Make the init method public.

c) Let the user call the init method after setting the CacheManagerEventListener.

New code becomes :

cacheManager = CacheManager.create(configFileName); cacheManager.setCacheManagerEventListener(this); cacheManager.init();

d) You should follow the standard way of adding and removing listeners (and allow multiple instances) :

addCacheManagerEventListener(…) removeCacheManagerEventListener(…)


Sourceforge Ticket ID: 1459359 - Opened By: monsieur_edi - 27 Mar 2006 15:10 UTC


Sourceforge Tracker 2009-09-21

Logged In: YES user_id=693320


a) is already how it works.

b) and c) This change would break all current uses of ehcache.

d) I am only supporting one CacheManagerEventListener, thus the set rather than add. There can however be multiple CacheEventListeners.

To do what you want to do, you can use a CacheManagerEventListener such as CountingCacheEventListener created with a factory like TestCacheManagerEventListenerFactory. You can find both of these in the test sources. You configure it in ehcache.xml as follows:

Then your this class can access the listener and process the events. Comment by: gregluck - 9 Apr 2006 00:58 UTC

Fiona OShea 2009-09-22

Re-opening so that I can properly close out these issues and have correct Resolution status in Jira