Anthony Jones wrote:
"Peter" <xd****@hotmail.comwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
Hi
The documentation for System.Web.Caching.Cache states that it is
"thread safe".
Does this mean that if I access System.Web.Caching.Cache from
several places in my application access to the items in the cache is
synchronised so I don't get problems with setting/getting the same
item at the same time?
Thats correct. Bear in mind though that any mutable reference types
included in the cache may not be be threadsafe themselves. Also the
cache is not really designed to support the idea of modifying an
existing value. Its designed to allow content to be added, read and
dropped in a threadsafe manner.
Thanks. I have one item I want to add to the cache, get from the cache,
and sometimes remove from the cache.
The item I want to add is a Dictionary containing various values.
I have one place which instantiates the dictionary, populates it, and
puts it in the cache.
I have several places which get the dictionary from the cache, use the
values in it (put not change the contents of it).
I have one place which will remove the dictionary from the cache. After
the Dictionary is removed, it will be re-instantiated, populated, and
put back in the cache.
Does that sound like it will give problems? What would happen if at one
place I get the dictionary from the cache, start performing tasks using
its contents, and then remove the dictionary from the cache while it is
still being used?
/Peter