akshayyn / cloning

Automatically exported from code.google.com/p/cloning
Other
0 stars 0 forks source link

Global cache object being updated inspite of cloning #26

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
In my web-application i am keeping a particular object in cache. Now whenever i 
am using this cache in front end i am making a clone and using it.

In the front end i have a checkbox which i can check and its value is contained 
in the object which i am keeping in cache.

In the initial case the checkbox in unchecked. But if i once check it then it 
is remaining as checked even it is coming as cloned object from cache.

This mean that the global cache object is being updated and cloning is not 
happening properly.

Is this a bug in the jar? Are there any provisions to address it?

Original issue reported on code.google.com by debrajpa...@gmail.com on 23 Dec 2013 at 3:15

GoogleCodeExporter commented 8 years ago
are you making a defensive copy of your object before caching it? There is a 
change that you're modifying the cached object, i.e. code holds a reference to 
the object which is in the cache too.

Original comment by kostas.k...@googlemail.com on 23 Dec 2013 at 3:25

GoogleCodeExporter commented 8 years ago
I am not making any copy before caching the object..it is required? What is 
defensive copy? It there any method in this jar which can do this? 

Original comment by debrajpa...@gmail.com on 24 Dec 2013 at 7:36

GoogleCodeExporter commented 8 years ago
well, you might need to do a copy (using deepClone) of the object before 
caching as well as after caching to avoid something like:

A a=new A();

cache(a);

a.setX(x); // the cached object was altered

Original comment by kostas.k...@googlemail.com on 24 Dec 2013 at 5:28

GoogleCodeExporter commented 8 years ago
Took a completely different approach of loading it first time through a job 
which solved the issue.

Original comment by debrajpa...@gmail.com on 3 Feb 2014 at 1:26

GoogleCodeExporter commented 8 years ago

Original comment by kostas.k...@googlemail.com on 3 Feb 2014 at 5:54