• New Feature
  • Status: Resolved
  • 2 Major
  • Resolution: Not a Bug
  • ehcache
  • drb
  • Reporter: silver
  • August 04, 2017
  • 0
  • Watchers: 2
  • August 04, 2017
  • August 04, 2017


the ehcache 2.10.3 did not support copy/deepclone the object when get the object from the ehcache,It returns reference. I suggest the ehcache.xml support the copy-on-read properties. If ok ,I want to pull the request.


Louis Jacomet Jacomet 2017-08-04

This is already supported.

Have a look at {{net.sf.ehcache.config.CacheConfiguration#copyOnRead}} or

<ehcache ...>
  <cache ... copyOnRead="true" ...>

Louis Jacomet Jacomet 2017-08-04

And for completeness, the documentation at http://www.ehcache.org/generated/2.10.4/html/ehc-all/#page/Ehcache_Documentation_Set%2Fco-pattrn_copy_cache.html%23

silver silver 2017-08-04

using the org.springframework.beans.BeanUtils.copyProperties ,the source object do not need to be Serializable. what about using this way :

Object target = Thread.currentThread().getContextClassLoader().loadClass(c.getClass().getName()).newInstance(); BeanUtils.copyProperties(source, target );

Louis Jacomet Jacomet 2017-08-04

Ah, that’s a very different thing indeed. The problem is it would make Ehcache depends on Spring which is not possible as we want to limit our dependencies.

What you are looking for will not be possible in Ehcache 2.x. However, the feature in Ehcache 3 will allow to do that since you can pass your own type for the copier - see http://www.ehcache.org/documentation/3.3/serializers-copiers.html#copiers

silver silver 2017-08-04

It is just an simple example. ehcache can implement the same logic as BeanUtils in spirng. do not need to dependency Spring

Louis Jacomet Jacomet 2017-08-04

Right and I missed an option in Ehcache that should allow you to use that if you want to - have a look at {{net.sf.ehcache.config.CopyStrategyConfiguration}} that will allow you to provide a custom copy strategy implementation, that can use whatever you want.