SQL Server Performance

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


Article Topics

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

USEFUL SITES :

ASP.NET Tutorials
Windows and SQL Azure Tutorials
Cloud Hosting Magazine
SharePoint Tutorials
Windows Server Help

Write for Us

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

A High Level Comparison Between Oracle and SQL Server - Part ...
A High Level Comparison Between Oracle and SQL Server - Part ...
A High Level Comparison Between Oracle and SQL Server - Part ...
A High Level Comparison Between Oracle and SQL Server

More     
 
Latest FAQ's

Add Node to A SQL Server failover Cluster failed with invalid ...
SQL Server Destination remote server error
Setting Up Data And Log Files For SQL Server
Will Check Constraints Improve Database Performance?

More     
   
Latest Software Reviews

dbForge Review
Spotlight on ApexSQL Diff - Server-based database comparison tool ...
Spotlight on ApexSQL Data Diff - Server-based database comparison tool ...
Spotlight on ApexSQL Doc 2008

More     

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

Caching in ASP.NET (Part II)

By : Joydip Kanjilal
Feb 28, 2007

Page 2 / 3


Cache Dependency and Cache Expiration Strategies

Cache dependency implies a logical dependency between the data in the Cache and physical data storage. Whenever the data in the physical storage changes, the dependency is broken, the cache is invalidated and the cached item is removed. This physical storage can be an XML file, a database, a flat file, etc.

The following is the complete syntax of using the CacheDependency class.

CacheDependency cacheDependency = new CacheDependency(fileObj, dateTimeObj);
Cache.Insert(key, value, cacheDependency);

As an example, you can set Cache dependency to an external Xml file as shown below:--

Cache.Insert("Country", objDataSet, new CacheDependency(Server.MapPath("Country.xml")));

You can also set a Cache dependency to a file in a remote system as shown below:--

CacheDependency objCacheDependency = new
CacheDependency(@"\\192.168.0.9\joydipk\Test.txt");

Similarly, you can also set Cache dependency on an entire folder. When the contents of the folder changes it will call an event handler for which you need to write the necessary code. In the earlier version of ASP.NET, the CacheDependency class was sealed. Hence you could not subclass this class to create your own Custom Cache dependencies. Things have now changed with ASP.NET 2.0 and the class is no longer sealed so you can create Custom Cache Dependencies by extending this class.

Cache Expiration relates to the removal of data in the cache after the durability of the cached item in the cache has expired. Cache expirations strategies can be Time Based, File Based or Key Based. The following sections discuss each of these strategies in detail with code examples.
 

Time Based Expiration

This is implemented by specifying a specific duration for which a cached item should remain in the cache. When the time elapses, the item is removed from the cache and subsequent requests to retrieve the item returns a null. This is used to specify a specific period of time for which the page would remain in the cache. The following statement specifies such expiration for a page in the code behind of a file using C# using the Cache API.

Response.Cache.SetExpires(DateTime.Now.AddSeconds(45));

This can also be accomplished by specifying the following in the page output cache directive as shown here.

<%@OutputCache Duration="45"
VaryByParam="None" %>

Time based expiration strategies can in turn be of the following two types:

        Absolute
        Sliding

In Absolute Expiration, the cache expires at a fixed time/date. For Sliding Expiration the cache duration is increased by the specified sliding expiration value each time the page is requested. Thus a heavily requested page will remain cached, whereas a less requested page will not be cached. Sliding Expiration is therefore useful in ensuring that the valuable resources allocated to the cache are allocated to the most heavily requested pages/items.

 The following is an example of Absolute Expiration:

Cache.Insert("Country", ds, null, DateTime.Now.AddMinutes(1), Cache.NoSlidingExpiration);

The cache is set to expire exactly two minutes after the user has retrieved the data.

The following is an example of Sliding Expiration:

Cache.Insert("Country", ds, null, Cache.NoAbsoluteExpiration, TimeSpan.FromMinutes(1));

Note that you cannot use both Absolute and Sliding expirations at the same time.


<< Prev Page     Next Page>>    








C# Help and Tutorials | PHP MySQL Tutorial | Sharepoint Tutorial | Azure Tutorial | Cloud Hosting Magazine | ASP.NET Tutorials | Windows Server Help | Windows Phone Pro | Silverlight Ace | Visual Studio Tutorials | Home | Peformance Articles | Audit Articles | Business Intelligence Articles | Clustering Articles | Developer Articles | Reporting Services Articles | DBA Articles | ASP.NET / ADO.NET Articles | SQL Server Training Videos | 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 | 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


              © 2010 Jude O'Kelly. All rights reserved