How can modify instance without Modifying caching instance?

Oct 25, 2011 at 9:49 AM
Edited Oct 25, 2011 at 9:49 AM

How can modify instance without Modifying caching instance?

Oct 25, 2011 at 10:27 PM

The caching block will return an instance of the object in the cache.  As it seems you found out, if you modify that instance it changes the object in the cache (since both references point to the same object).

The first solution is not to modify the objects.  Sounds simple but you can recommend this as a standard for your application.
The second solution is to implement a Clone method for your object.  If you didn't write the object then you can wrap that object in your own object and then implement Clone.

Also, note that it's not recommended to implement ICloneable.

 

--
Randy Levy
Enterprise Library support engineer
entlib.support@live.com