Hello,
I am using Spring's @Cachable feature for storing objects into ehcache's big memory version which can survive server restart.
Problem: I want to get the object from cache, modify some attributes. The modified attributes are visible when the objects are retrieved at a later point in time as long as server is not re-started. But the moment server is re-started, the modified attribute values are lost.
Below is the code
Is there any mechanism using spring to specify that the modified objects needs to be put back into cache again? (so that they can be serialized, and hence survive server re-start)
I am using Spring's @Cachable feature for storing objects into ehcache's big memory version which can survive server restart.
Problem: I want to get the object from cache, modify some attributes. The modified attributes are visible when the objects are retrieved at a later point in time as long as server is not re-started. But the moment server is re-started, the modified attribute values are lost.
Below is the code
Code:
@Cacheable(value = "myChache")
public MyObject profileMyObject(String attr1,
long attr2) {
MyObject mo = new MyObject();
mo.setAttr1(attr1);
mo.setAttr2(attr2);
return mo;
}
Code:
public myOtherMethod(){
MyObject mo1 = profileObject("foo",1);
mo1.setMyOtherAttribute1("some value");
// after server restart above attribute is not stored!!!
// but mo1.getAttr1() and mo1.getAttr2() have the values..
// only otherAttribute values are lost!!
}
Code:
<cache name="myChache" maxEntriesLocalHeap="10000"
maxEntriesLocalDisk="30000" eternal="true">
<persistence strategy="localRestartable"
synchronousWrites="true" />
<searchable>
<searchAttribute name="attr1" expression="value.getAttr1()" />
<searchAttribute name="attr2" expression="value.getAttr2()" />
<searchAttribute name="attr3" expression="value.getAttr3()" />
</searchable>