Caching application data in asp net Part 126

  • دعنا نشارك هذا :
ترتيب الدرس : 126
المدة : 00:17:27
التحكم :
Text version of the video
http://csharp-video-tutorials.blogspot.com/2013/02/caching-application-data-in-aspnet-part.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-126-caching-application-data.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 parts 119 to 125 of the asp.net video tutorial, we discussed about
1. Caching webforms
2. Caching multiple responses of webforms
3. Fragment caching using user controls
4. Caching multiple versions of usercontrols

Please watch these videos, from the asp.net video tutorial using the link below
http://www.youtube.com/playlist?listPL6n9fhu94yhXQS_p1i-HLIftB9Y7Vnxlo

In this video we will discuss about caching application data. It is possible to store application data in the web server memory, using the CACHE object, so that the data can be retrieved faster. For example, let us say, we have a stored procedure that takes 5 seconds to execute and return data. We can cache the data returned by this stored procedure with in an asp.net web application using the CACHE object, so that, next time when we try to access the data, we can get it from the cache, rather than reprocessing the stored procedure again.

We will be using "tblProducts" table for this demo. If you need the script to create and populate this table, please refer to Part 122, using the link below.
http://csharp-video-tutorials.blogspot.com/2013/01/fragment-caching-in-aspnet-part-122.html

Text version of this video is present at the following link
http://csharp-video-tutorials.blogspot.com/2013/02/caching-application-data-in-aspnet-part.html

The following stored procedure takes 5 seconds to execute and return data. We are using WAITFOR DELAY, to introduce artificial query processing time of 5 seconds.
CREATE Procedure spGetProducts
as
Begin
Waitfor Delay '00:00:05'
Selectfrom tblProducts
End

Copy and paste the following code in WebForm1.aspx.cs. The code is well documented and is self explanatory.
protected void btnGetProducts_Click(object sender, EventArgs e)
{
DateTime dtStartDateTimeDateTime.Now;
System.Text.StringBuilder sbMessagenew System.Text.StringBuilder();
// Check if the data is already cached
if (Cache["ProductsData"] ! null)
{
// If data is cached, retrieve data from Cache using the key "ProductsData"
DataSet ds(DataSet)Cache["ProductsData"];
// Set the dataset as the datasource
gvProducts.DataSourceds;
gvProducts.DataBind();
// Retrieve the total rows count
sbMessage.Append(ds.Tables[0].Rows.Count.ToString() + " rows retrieved from cache.");
}
// If the data is not cached
else
{
// Get the data from the database
DataSet dsGetProductsData();
// Cache the dataset using the key "ProductsData"
Cache["ProductsData"]ds;
// Set the dataset as the datasource
gvProducts.DataSourceds;
gvProducts.DataBind();
sbMessage.Append(ds.Tables[0].Rows.Count.ToString() + " rows retrieved from database.");
}
DateTime dtEndDateTimeDateTime.Now;
sbMessage.Append((dtEndDateTime - dtStartDateTime).Seconds.ToString() + " Seconds Load Time");
lblMessage.TextsbMessage.ToString();
}

private DataSet GetProductsData()
{
string CSConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
SqlConnection connew SqlConnection(CS);
SqlDataAdapter danew SqlDataAdapter("spGetProducts", con);
da.SelectCommand.CommandTypeCommandType.StoredProcedure;

DataSet dsProductsnew DataSet();
da.Fill(dsProducts);

return dsProducts;
}

In this video, we discussed about storing application data in cache, using direct assignment. That is using a key and assiging value to it, as shown below.
Cache["ProductsData"]ds

In our next video, we will discuss about all the other options that are available, to store data in the Cache object.

سيتم تفعيل التعليقات قريبا

y
Sep 23, 2020 07:32:26
youtube