In Ehcache 2.x, when using both heap and disk storage, calling remove()
on the cache not only removes the entry from memory but also clears the corresponding data from the disk (i.e., the file content is cleared from the disk).
Cache personCache = cacheManager.getCache("personCache"); personCache.remove("person1");
However, in Ehcache 3.x, I am using the following. When I call personCache.remove("person1")
or personCache.removeAll()
, it does not clear the disk file content. I have checked the internal implementation of the remove()
method, and unlike Ehcache 2.x, it does not include any shrinkFile()
or equivalent logic to remove the data from the disk storage.
On the other hand, calling destroyCache()
does delete the associated disk directory, but that is not an option in my use case. I also tried clear() but it also did not work.
I need to clear disk file content without closing the CacheManager
and without using destroyCache()
. This is because the personCache
is shared among multiple users, and destroying it while others are accessing it would break the functionality.
Could you please suggest how I can clear the disk file in Ehcache 3.x, without closing the CacheManager
or destroying the entire cache?
Please refer to the attached code which I have used for configuration.
Any help is much appreciated.
Thanks & Regards
Abhishek