Site sponsored by: Idera Try Idera’s new SQL admin toolset
SQL Server Performance

  • Home
  • Articles
  • Forums
  • Tips
  • Quiz
  • FAQ's
  • Blogs
  • Software
  • Books
  • About Us
RSS Feeds
Sign in | Join


Article Topics

All Articles
Performance Tuning
Audit
Business Intelligence
Clustering
Reporting Services
Developer
General DBA
ASP.NET / ADO.NET

Write for Us

Share you SQL Server knowledge with others and raise your profile in the community More...
Latest Articles

Resource Governor in SQL Server 2008
Tweaks in SQL Server Reporting Services
Configure Filestream in SQL Server 2008
Capture DDL Changes using Change Data Capture with SQL Server 2008 ...

More     
 
Latest FAQ's

SQL Server Reporting Server (SSRS) service is failing to start ...
Cannot Start SQL Server Service
Users are able to connect to report manager but not able ...
Errors when SQL Server Snapshot Replication is Running

More     
   
Latest Software Reviews

Spotlight on ApexSQL Doc 2008
ApexSQL Enforce
Embarcadero Change Manager
SQL Server DBA Dashboard

More     

articles >> asp.net / ado.net >> Caching in ASP.NET (Part I) ...

Caching in ASP.NET (Part I)

By : Joydip Kanjilal
Feb 18, 2007

Page 2 / 3

Declarative Approach

The declarative specification here implies that Page Output Caching is specified at the design time by adding the OutputCache directive in the web page source.

The following is the complete syntax of page output caching directive in ASP.NET.

<%@ OutputCache Duration="no of seconds"
Location="Any | Client | Downstream | Server | None"
VaryByControl="control"
VaryByCustom="browser |customstring"
VaryByHeader="headers"
VaryByParam="parameter" %>

We can specify output caching in an aspx page at design time using the OutputCache directive as shown below.

<%@OutputCache Duration="25" VaryByParam="none" %>

The VaryByHeader and VaryByCustom parameters of the OutputCache directive are used to enable customization of the page's look or content based on the client that is accessing them. The cache duration is a mandatory parameter and specifies how long (in seconds) the web page remains in the cache memory. The VaryByParam parameter is optional and is used to cache different views of the page, i.e., whether the cached page would have different versions based on a specific parameter. A value of * in the same parameter indicates that the page would be cached based on all the Get/Post parameters. We can also specify one or more Get/Post parameter(s). The VaryByParam parameter is particularly useful in situations where we require caching a page based on some pre-defined criteria. As an example, we might require to cache a specific page based on the PatientID. The OutputCache directive needs to be specified as shown below.

<%@OutputCache Duration="10" VaryByParam="PatientID" %>  

The VaryByParam parameter can also have multiple parameters as shown in the example below.

<%@OutputCache Duration="20" VaryByParam="PatientID;ProviderID" %>

The location parameter in the OutputCache directive is used to specify the cache location, i.e., from where the client received the cached page. This should be one of the possible four OutputCacheLocation enumeration values, namely, Any, Client, Downstream, None, Server. An example is given below.

<%@OutputCache Duration="10" VaryByParam="*" Location = "Any"%>  

Programmatic Approach

Page Output Caching can also be specified programmatically using the Response.Cache.SetCacheability method. The parameters to this method can be “NoCache”, “Private”, “Public” or “Server”. Refer to the code example below that illustrates how to set a page’s cache ability programmatically:

Response.Cache.SetCacheability (HttpCacheability.Server);

It is also possible to set the OutputCache on all the pages in an ASP.NET application programmatically in the Global.asax page. Refer to the code snippet that follows:--

void Application_BeginRequest(object sender, EventArgs e)
    {
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.Server);
    }

The source code given in the above code snippet sets the cache ability programmatically in the BeginRequest event of the application's global class.


<< Prev Page     Next Page>>    








Home | Peformance Articles | Audit Articles | Business Intelligence Articles | Clustering Articles | Developer Articles | Reporting Services Articles | DBA Articles | ASP.NET / ADO.NET Articles | DBA FAQ's | Developer Peformance FAQ's | DBA Peformance FAQ's | Developer FAQ's | Clustering FAQ's | Error Messages | Audit Tool Reviews | Backup Tool Reviews | Coding Tool Reviews | Compare Tool Reviews | Documentation Tool Reviews | Design Tool Reviews | Monitoring Tool Reviews | Log Tool Reviews | Reporting Tool Reviews | Clustering Tool Reviews | Security Tool Reviews | Change Management Tool Reviews | Remote Access Tool Reviews | Book Reviews | Security Tool Reviews | QDPMA Performance Tuning | ADO.NET / ASP.NET | Administration | Analysis/OLAP Services | Application Development | Configuration | Components | ETL | Hardware | High Availability | Hints | Index | Misc | Operating Systems | Performance Tuning | Replication | T-SQL | Views


              © 1999-2008 by T10 Media. All rights reserved