ASP.NET Micro Caching: Benefits of a One-Second Cache
page 3 of 7
by Steven Smith
Feedback
Average Rating: 
Views (Total / Last 10 Days): 50872/ 76

Test Page Without Caching

I created a simple ASP.NET page that calls "SELECT * FROM Products" against a local instance of the Northwind database, fills a DataSet with the result, and binds it to a DataGrid.  To limit the web server overhead, I disabled ViewState and SessionState on the page.  The page's code without caching was as follows:

Default.aspx

<%@ Page language="c#" Codebehind="Default.aspx.cs" AutoEventWireup="false" Inherits="MicroCache._Default" EnableSessionState="false" EnableViewState="false" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
 <HEAD>
  <title>Products</title>
 </HEAD>
 <body MS_POSITIONING="FlowLayout">
  <form id="Form1" method="post" runat="server">
   <asp:DataGrid id="DataGrid1" runat="server"></asp:DataGrid>
  </form>
 </body>
</HTML>

The codebehind performed the logic as follows:

Default.aspx.cs (excerpt)

 public class _Default : System.Web.UI.Page
 {
  protected System.Web.UI.WebControls.DataGrid DataGrid1;
 
  private void Page_Load(object sender, System.EventArgs e)
  {
   BindGrid();
  }

  private void BindGrid()
  {
   SqlConnection conn = new SqlConnection("server=localhost;database=northwind;integrated security=true");
   SqlDataAdapter cmd = new SqlDataAdapter("SELECT * FROM Products", conn);
    DataSet ds = new DataSet("Products");
   cmd.Fill(ds);
   DataGrid1.DataSource = ds;
   DataGrid1.DataBind();   
  }
...
}


View Entire Article

User Comments

Title: Effective   
Name: Sangam Uprety
Date: 2009-08-20 7:36:29 AM
Comment:
I tested the same using badboy and saw the differences myself. Page level output cache improves performance, like the caching of data in BLL. I just wonder why there is so few discussions on this technique. And is 1 second the minimum possible page output cache duration? Further, what about pushing it upto 10 seconds?
Title: good   
Name: mcgyver
Date: 2009-07-08 1:14:06 PM
Comment:
my company is an equities broker and we have an ajax webbroker. There are about 100 more liquid assets, but 1000s of clients. Probably this aproach will diminish our hardware uses
Title: Simultaneous requests   
Name: The Chief
Date: 2006-05-18 8:10:20 AM
Comment:
Hi

If it takes 0.5 seconds to load data and render the page and the server receives 20 requests within this time, does asp.net hold off processing the other 19 requests for the same page until it has finished rendering and caching the output from the first of these 20 page requests?

Your results would suggest that this is indeed what is happening but would appreciate confirmation of this.

We use caching on a busy e-commerce site, but there is still a bit of a hit on the server when the site restarts as all the output on each different category page is loaded and cached at the same time. I'm wondering whether the same data is being loaded twice via multiple requests.

Thanks
Title: Caching   
Name: Arpi
Date: 2006-02-09 6:57:03 AM
Comment:
This article explain right.Hence I want to know how can we stop caching of the system
Title: Not So Silly   
Name: Steven Smith
Date: 2005-07-28 8:32:35 AM
Comment:
Not so - consider a news site like CNN.com. With their traffic I'm sure certain articles are read more than 1/second, and I'm willing to bet their articles are stored in a database. The same is true for an eBay auction nearing its end, or a popular Amazon.com book. There are plenty of large scale applications that could theoretically benefit from this technique. That said, you have to test your own application using realistic usage data for your app, then set the cache duration to something that makes sense for you.
Title: Silly   
Name: Cookie Monster
Date: 2005-07-28 3:05:54 AM
Comment:
This is silly. Only in this test would a 1 second cache make this large of a difference. In the real world, users wouldn't be accessing the exact same piece of data so often, so basically every request would end up a cache miss.

Product Spotlight
Product Spotlight 





Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-04-23 4:01:53 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search