Cache.Insert Method & Call Back function
System.Web.Cache has a Insert method where by you can insert values inside the cache. This method has various overloads and what is worth knowing about one of its overload is the Callback function it provides... You can provide your own callback function here which will be triggered when a the item you just inserted is removed from the cache. This callback function gives you the key of the item removed, the item itself as well as the reason why it was removed. The reason is given back as an enum which can be either dependency changed, expired, removed or underused...
You can use this callback function to write your custom logic on what you would want to do when the item gets removed. for e.g. To retrieve this item from where ever is a CPU intensive job, you do not want it to be done at runtime... Then within this call back function you can spawn another thread to restore this item into cache...
Alternatively if the item was dependant on a file and file change was the reason it got removed you can do you alternate processing... You can also do a logging of cache item removal by anyone in the application by using this callback...
In short this is a useful callback function and you should look upon the options...
Refer the link for further information: Click Here
PS: A friend of mine (Deepa C) sends a good morning mail every morning... She has some amazing information and my favorite Calvin & Hobbes cartoon strip in the mail every time, today she wrote a notable information which I thought I should share with you folks... "The slogan on New Hampshire license plates is 'Live Free or Die'. These license plates are manufactured by prisoners in the state prison in Concord." (for non-US readers - Vehicle plates in most of the states of US carry a slogan representing the state)
No comments:
Post a Comment