Remove data from Caching for a key

Topics: Caching Application Block
Jun 13, 2013 at 9:53 AM
Hi All

I am using the ICacheManager of Microsoft.Practices.EnterpriseLibrary.Caching for managing the cache. We add the application reference data against the key.

But the application also have some screens to update this master data and that time this data in cache must be refreshed.

I want to know what is the best way to remove the data against the key from the cache. We also need to make sure that while we are removing the data someone other method must not read the data.

Thanks for your help.
Jun 14, 2013 at 6:53 AM
To remove data call the Remove(string key) method. Or if you want to perform an update call the Add method -- this will replace any item in the cache with a matching key (or add the new item if it is not found in the cache).

Internally, when any of Add, Remove or GetData methods are called the cache is locked and then the cache item specified by the given key is exclusively locked. So a specific cache item can only be accessed (updated, removed, or read) by one thread at a time. In most scenarios this is adequate but you need to expand on "removing the data". Is this just a method call to the cache? Or is there more of a logical process that is occurring?

Some reading:

The Caching Application Block
A Cache Advance for your Applications

Randy Levy
Enterprise Library support engineer
Support How-to