تقييمات الطلاب
( 5 من 5 )
١ تقييمات
فيديو شرح Cache dependency on files in asp net Part 129 ضمن كورس ASP.net شرح قناة kudvenkat، الفديو رقم 129 مجانى معتمد اونلاين
Text version of the video
http://csharp-video-tutorials.blogspot.com/2013/02/cache-dependency-on-files-in-aspnet.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-129-cache-dependency-on-files.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 cache dependency on files in asp.net. Let us understand this with an example. Create an asp.net web application. Add a folder with name "Data" to your web application. Right click on the "Data" folder and add an xml file with name "Countries.xml".
Countries.xml file and the HTML of webform1.aspx can be found on my blog at the following link
http://csharp-video-tutorials.blogspot.com/2013/02/cache-dependency-on-files-in-aspnet.html
The following code reads xml data from "Countries.xml" file into dataset which is then cached. Notice, that we are using "cache" object's "Insert()" method to cache the DataSet. Since we are passing "null" as the argument for "CacheDependency" parameter of the "Insert()" method, when the data in "Countries.xml" file changes, the data in the cache is unaffected.
protected void btnGetCountries_Click(object sender, EventArgs e)
{
// Check if the data is already cached
if (Cache["CountriesData"] ! null)
{
// If data is cached, retrieve data from Cache
DataSet ds (DataSet)Cache["CountriesData"];
// Set the dataset as the datasource
gvCountries.DataSource ds;
gvCountries.DataBind();
// Retrieve the total rows count
lblMessage.Text ds.Tables[0].Rows.Count.ToString() + " rows retrieved from cache.";
}
// If the data is not cached
else
{
// Get data from xml file
DataSet ds new DataSet();
ds.ReadXml(Server.MapPath("~/Data/Countries.xml"));
//Cache Countries and set dependency on file
Cache.Insert("CountriesData", ds, null, DateTime.Now.AddSeconds(20), System.Web.Caching.Cache.NoSlidingExpiration);
// Set the dataset as the datasource
gvCountries.DataSource ds;
gvCountries.DataBind();
lblMessage.Text ds.Tables[0].Rows.Count.ToString() + " rows retrieved from the file.";
}
}
When the data in Countries.xml file changes, we want the data in the cache to be removed automatically. For this to happen we need to establish a dependency on the xml file as shown below.
Cache.Insert("CountriesData", ds, new CacheDependency(Server.MapPath("~/Data/Countries.xml")), DateTime.Now.AddSeconds(20), System.Web.Caching.Cache.NoSlidingExpiration);
Now run the application. After the dataset is cached, change the xml file and click "Get Countries" button. Notice that the data is now retrieved from file directly, as the dataset is removed from cache.