Hi,
say I am adding lots of things to the cache, and I want a callback when each
of them is removed
can I just create one instance of my delegate and pass it in every time I
insert something into the cache, or do I have to create a new instance of
the delegate each time?
i.e. will this work?
CacheItemRemovedCallback onRemove = new
CacheItemRemovedCallback(this.RemovedCallback);
Cache.Add(object1,...,onRemove);
Cache.Add(object2,...,onRemove);
Cache.Add(object3,...,onRemove);
TIA
Andy
Brock Allen - 08 Aug 2005 16:24 GMT
You can pass the same delegate.
Can I ask what you want to do in the callback? The callback is not for repopulating
the item in the cache, mind you :)
-Brock
DevelopMentor
http://staff.develop.com/ballen
> Hi,
>
[quoted text clipped - 15 lines]
>
> Andy
Andy Fish - 08 Aug 2005 16:33 GMT
Thanks for the reply
I just need to log the fact that the item has been removed and clear up some
other resources that were associated with the item
> You can pass the same delegate.
> Can I ask what you want to do in the callback? The callback is not for
[quoted text clipped - 23 lines]
>>
>> Andy
Bill Priess (MCP) - 15 Aug 2005 23:26 GMT
Actually, the CacheItemRemovedCallback can be used to repopulate the item to
cache if desired. ;-)
Bill Priess, MCP
> You can pass the same delegate.
> Can I ask what you want to do in the callback? The callback is not for
[quoted text clipped - 23 lines]
>>
>> Andy
Brock Allen - 16 Aug 2005 01:52 GMT
I disagree. While you can, I don't think it's necessary or a good practice.
It all depends upon what you're trying to do, but in general I'd say no.
The reason is this: There is a window of time between when the item is removed
from the cache and when your callback executes where the cache is empty.
If there's a request in that timeframe then the request will not find the
cache entry. This means the code accessing the cache entry should always
be written to check the cache and if there's no entry it should go back to
the database to fetch the entry and repopulate the cache. Well, since that
code has to be written that way, then it's redundant for the code in the
CacheItemRemoveCallback to do the same thing. Since it's redundant, I'd say
that it's unnecessary and something you don't need to do.
-Brock
DevelopMentor
http://staff.develop.com/ballen
> Actually, the CacheItemRemovedCallback can be used to repopulate the
> item to cache if desired. ;-)
[quoted text clipped - 26 lines]
>>> TIA
>>> Andy