Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Caching / August 2005

Tip: Looking for answers? Try searching our database.

when to instantiate CacheItemRemovedCallback delegate

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Andy Fish - 08 Aug 2005 15:15 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.