我有以下从缓存返回数据的方法。
Customer customer = customerDao.findByName("Carl");
它只返回一个Customer
带有name="Carl"
. 当我进行以下更改时:
customer.setName("Ron");
然后我再次调用该方法
Customer customer = customerDao.findByName("Carl");
它返回空值。我没有进行任何持久化或更新操作,并且缓存的对象被直接更改。我尝试在 ehcache 配置中使用 copyOnRead 属性,但它没有帮助。
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd">
<!-- default configuration -->
<defaultCache maxElementsInMemory="1000000"
eternal="true" overflowToDisk="false" copyOnRead="true" />
</ehcache>
有什么办法可以强制 ehcache 从缓存中复制对象?
谢谢