Student Reviews
( 5 Of 5 )
1 review
Video of Reloading or refreshing cache automatically, when cached data is removed Part 130 in ASP.net course by kudvenkat channel, video No. 130 free certified online
Text version of the video
http://csharp-video-tutorials.blogspot.com/2013/02/reloading-or-refreshing-cache.html
Healthy diet is very important both for the body and mind. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking our YouTube channel. Hope you can help.
https://www.youtube.com/channel/UC7sEwIXM_YfAMyonQCrGfWA/?sub_confirmation1
Slides
http://csharp-video-tutorials.blogspot.com/2013/08/part-130-reloading-or-refreshing-cache.html
All ASP .NET Text Articles
http://csharp-video-tutorials.blogspot.com/p/free-aspnet-video-tutorial.html
All ASP .NET Slides
http://csharp-video-tutorials.blogspot.com/p/aspnet-slides.html
All Dot Net and SQL Server Tutorials in English
https://www.youtube.com/user/kudvenkat/playlists?view1&sortdd
All Dot Net and SQL Server Tutorials in Arabic
https://www.youtube.com/c/KudvenkatArabic/playlists
In this video we will discuss about
1. When and how to use "CacheItemRemovedCallback" delegate
2. Reloading or refreshing cache automatically, when cached data has expired
Code samples used in the demo, is available on my blog at the following link
http://csharp-video-tutorials.blogspot.com/2013/02/reloading-or-refreshing-cache.html
Explanantion of code in btnLoadCountriesAndCache_Click() event handler:
When you click "Load Countries & Cache" button, the xml data is read from "Countries.xml" into a dataset, which is then cached. Notice that, before we cache data using the "Cache" objects "Insert()" method, we are creating an instance of CacheItemRemovedCallback delegate. To the constructor of this delegate, we are passing, the name of the function that we want to have executed automatically, when the cache item is removed from cache. An item may be removed automatically, from cache, when any of the following conditions are true
The cached item has expired.
The cache is full.
There is a cache dependency, and the item, that the cache object is dependent on has changed.
The delegate object is then passed as an argument for CacheItemRemovedCallback delegate parameter of the insert() method. So, when the item, with cache key"CountriesData" is removed the delgate gets invoked, which inturn will automatically invoke, the function it is pointing to, in our case "CacheItemRemovedCallbackMethod()".
Explanantion of code in CacheItemRemovedCallbackMethod() function:
This method gets invoked automatically, whenever the cached item is removed from cache. So, this is the opportunity for us to decide what we want to do when the cached item is removed from cache. For example, in this method the following 2 lines get the key of the item that is removed from the cache and the removed reason, and stores the message in another cache object, with key"CacheStatus".
string dataToStore "Cache item with key \"" + key + "\" is no longer present. Reason " + reason.ToString();
Cache["CacheStatus"] dataToStore;
Alternatively we can also store information about the removed cach object, in a database table. The ado.net code that does this is commented.
Finally we can also reload data ino cache, from the XML file. The code to reload data into cache, is also commented.
Explanantion of code in btnGetCountriesFromCache_Click() event handler:
The code in "Get Countries from Cache" button click event handler is staright forward. We check if countries data is present in cache, and if it is, we retrieve the data from cache and display in gridview control.
Code in btnRemoveCachedItem_Click() and btnGetCacheStatus_Click() is self explanatory.