Yes, your code clears all the caches that you have in your cacheManager. The ehcache documentation says: void clearAll() Clears the contents of all caches in the CacheManager, but without removing any caches
If you want to test it, you can add some elements to your cache, call clearCache()
, and then try to get the values. The get()
method should return only null
.
You cannot add values ββdirectly to cacheManager, it just manages the caches specified in the configuration file. (The default is ehcache.xml, you can get it on the ehcache homepage.) You can also add the cache programmatically, without even knowing anything about the configuration.
CacheManager cacheManager = CacheManager.getInstance(); Ehcache cache = new Cache(cacheManager.getConfiguration().getDefaultCacheConfiguration()); cache.setName("cacheName"); cacheManager.addCache(cache);
To add a value to the cache, you must create an element: Element element = new Element(key, value)
and just call cache.put(element)
. If your cache variable is no longer visible, but your cacheManager is, you can do the same with cacheManager.getCache(cacheName).put(element)
Hope this helps ...
source share