Re: Cache problem



I found this using Google:
========================================================
This is the expected behaviour. What you really get from of the cache is a
reference to the object in cache. Changes to this object are seen by
everyone that has a reference to this object.

You could solve this by wrapping the Cache access in a method that gets the
excel object from the cache and then clones it, before giving a reference to
the clone to you. But this might not be enough, since this is only a shallow
copy (objects referenced in the original are not copied, just their
references). Depends on how the excel object is implemented.
========================================================

I believe the shallow copy is my problem as I change one of the internal
objects using a reference.
--
Joe Fallon



"Joe Fallon" <jfallon1@xxxxxxxxxxxxxxxxxx> wrote in message
news:OAufzJtZFHA.2984@xxxxxxxxxxxxxxxxxxxxxxx
> I have a class which is stored in the cache.
> When I retrieve it from cache I return a clone of the class so that I do
not
> keep a reference to the cached item. (That is the theory anyway.)
>
> When I modify the cloned object and then navigate to another page, the
data
> in the cache is modified with my changes anyway!
>
> So when I go to another page and expect a "clean" copy of my class to be
> retrieved from the cache, it is "dirty" with the changes made on a
different
> page.
>
> Can someone please explain what is happening here?
> I thought that returning a clone would break the reference to the cached
> object.
>
> I would hate to have to abandon this technique, but if it doesn't work....
> --
> Joe Fallon
>
>
>


.



Relevant Pages

  • Re: c# object caching and reference counting
    ... I need to cache various resource objects such as images for example, ... (wich could be considered documents for ease of discusion) ... I realy dont want to have to keep a track of seperate reference count as ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Load Testing Errors
    ... Another thing to check when you get null reference errors in an ASP.NET ... application, but ONLY under load, is whether the objects on which you're ... if (someObjectKey is in the cache) { ... lower volumes, then either your cache expires very frequently, or there is ...
    (microsoft.public.dotnet.general)
  • Re: Load Testing Errors
    ... Another thing to check when you get null reference errors in an ASP.NET ... application, but ONLY under load, is whether the objects on which you're ... if (someObjectKey is in the cache) { ... lower volumes, then either your cache expires very frequently, or there is ...
    (microsoft.public.dotnet.security)
  • Re: Load Testing Errors
    ... Another thing to check when you get null reference errors in an ASP.NET ... application, but ONLY under load, is whether the objects on which you're ... if (someObjectKey is in the cache) { ... lower volumes, then either your cache expires very frequently, or there is ...
    (microsoft.public.dotnet.framework.performance)
  • c# object caching and reference counting
    ... I need to cache various resource objects such as images for example, ... (wich could be considered documents for ease of discusion) ... I realy dont want to have to keep a track of seperate reference count as ...
    (microsoft.public.dotnet.languages.csharp)