0

I'm in the process of upgrading JavaLite ActiveJDBC from EHCache 2.x to v 3.x. It looks APIs changed dramatically, and I can find equivalents of what I need in v 3.x, except for one: How to clear all caches? For example, in v2.x, I could do this:

net.sf.ehcache.CacheManager cacheManager = net.sf.ehcache.CacheManager.create();
//... code
cacheManager.removalAll();

How can I do this in EHCache 3?

ipolevoy
  • 5,432
  • 2
  • 31
  • 46

1 Answers1

2

Clarification: CacheManager.removalAll() is a method that not only clear caches, but removes them completely. It is deprecated in the latest version and replaced with CacheManager.removeAllCaches() to better indicate its purpose. Caches will no longer be alive and cannot be used anymore if you were to keep a reference to one of them.

The equivalent in Ehcache 3 would be to invoke: CacheManager.close() which would close all caches and then release all resources held by the CacheManager.

Hard to conclude with the disconnect between what I understand the stated goal to be (clear data from caches) and the Ehcache 2 method used (remove all caches) if Ehcache 3 satisfies it.

Louis Jacomet
  • 13,661
  • 2
  • 34
  • 43
  • Thanks for the answer. So, in version 3, I would: `cacheManager.close();` to release all caches. Should I then loose reference to this object? Also, if I need to recreate it, I would then create a new instance of CacheManager, correct? – ipolevoy Dec 09 '15 at 15:57
  • No, in 3 the lifecycle is explicit and properly handled. You can simply invoke CacheManager.init() to re-enable it, it will also re-initialise all caches configured in it. – Louis Jacomet Dec 11 '15 at 11:10
  • So, the method `CacheManager.init()` will clear existing caches too? – ipolevoy Dec 11 '15 at 16:11
  • Absolutely not, `CacheManager.init()` will properly initialize a cache manager, either at time of creation or after it has been `CacheManager.close()`. – Louis Jacomet Dec 14 '15 at 09:31