I recently learned about Unmodifiable Map that returns an unmodifiable copy of the Map. Is there any such implementation that prevents the modification of data of Cache entries in EhCache?
Asked
Active
Viewed 166 times
0
-
Do you want to prevent modifications to objects returned from cache or do you want to protect contents of cache? By default cache returns references to actual contents, but you can configure it to create copies on read: http://www.ehcache.org/documentation/2.8/configuration/configuration.html#copyonread-and-copyonwrite-cache-configuration – Sami Korhonen Jul 12 '17 at 17:55
1 Answers
0
There is no out of the box support for a read-only Cache
in Ehcache 2.x or 3.x as I understand your request.
In Ehcache 2.x you could roll your own by using a cache decorator and then making them available to the CacheManager
by using CacheManager.addDecoratedCache
In Ehcache 3.x there is no built-in support for decorated caches, so you would have to handle that yourself. Note that anyway since there is no longer a CacheManager
singleton, this is not as bad as it sounds with regards to the way you would share the decorated cache with your application components.

Louis Jacomet
- 13,661
- 2
- 34
- 43