Hi All,
i have an query .is ehcache dynamic caching?
let's say ,i am caching 100 rows of a table which i store into a list object and in turn cached.if any those records are updated in the table does ehcache mechanism identifyes itself before getting from cache.
i appreciate all your help
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
No, Ehcache cannot detect that change, but it may seem to work in some circumstances.
I think you say you wish to do this:
List list = new ArrayList();
list.add(obj1);
list.add(obj2);
//make the Ehcache Element
cache.put(new Element("key", list));
//alter contents of list, e.g.
obj1.change();
//or
list.add(obj3);
========
If you then access the list via cache:
List list2 = (List) cache.get("key").getValue();
then list2 WILL PROBABLY contain obj1/2/3 and the change in obj2.
BUT this behaviour is not guaranteed nor recommended. It only works because of Java's object reference model.
For instance, if you were to use Ehcache to replicate the cache to another node on the network, then this change would NOT be replicated. If your cache became full, then that List could have been moved to disc and if it is then read in from disc you would get the old copy.
You should do this after any change to the list:
cache.put(new Element("key", list));
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi All,
i have an query .is ehcache dynamic caching?
let's say ,i am caching 100 rows of a table which i store into a list object and in turn cached.if any those records are updated in the table does ehcache mechanism identifyes itself before getting from cache.
i appreciate all your help
No, Ehcache cannot detect that change, but it may seem to work in some circumstances.
I think you say you wish to do this:
List list = new ArrayList();
list.add(obj1);
list.add(obj2);
//make the Ehcache Element
cache.put(new Element("key", list));
//alter contents of list, e.g.
obj1.change();
//or
list.add(obj3);
========
If you then access the list via cache:
List list2 = (List) cache.get("key").getValue();
then list2 WILL PROBABLY contain obj1/2/3 and the change in obj2.
BUT this behaviour is not guaranteed nor recommended. It only works because of Java's object reference model.
For instance, if you were to use Ehcache to replicate the cache to another node on the network, then this change would NOT be replicated. If your cache became full, then that List could have been moved to disc and if it is then read in from disc you would get the old copy.
You should do this after any change to the list:
cache.put(new Element("key", list));