Caching Pages
Home Up

 

Home

Up

ourmission
theweb.gif (1103 bytes)
booksandbibles16
thenewsroom
governmentrm.gif (1147 bytes)
searchpage
tutorials
webtools
websecurity

What is the Web?

Privacy & Disclaimer
copyrights
notices
HOME

Visitors Since
Aug - 2004

Hit Counter

 

Caching Pages versus caching things?

 

How can we determine where things are cahced?

Client
<%@ OutputCache Duration="60" Location="Client" %>

Server
<%@ OutputCache Duration="60" Location="Server" %>

No Cache
<%@ OutputCache Location="None" %>


There is also a forth option, to let the page or thing be cached in a public or shared location such as a proxy server.
 

The above are directives to use in the page. There are additional coding options that allow you to use class directives.
 

How do we know, which is which and what is getting cached?

There are (as of this note) three defined caching methods.

  1. Output caching: Full Page
  2. Fragment caching: individual user controls (either by page or website)
  3. Data caching: Object caching (extremely granular)

 

Full Page Caching

Simple output caching, is invoked by including the @OutputCache directive at the top of your .aspx page.

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

This will cache the page in memory for 20 minutes (1,200 seconds).

When one of thes above methods is added to the ASP.Net page, the response page is saved in the cache. In other words, will be subsequently pulled from memory instead of being re-created from the server's drive.

Subsequent GET, POST and HEAD requests for the page then refer to the cache until the cache expires as indicated by the duration paramater.
 

Fragment Caching

To save server memory, and have a little more control, you could use HttpCachePolicy class. This is done by adding Response.Cache.[option].

Additionally, you can set the expiration time like this.


Response.Cache.SetExpires( DateTime.Now.AddSeconds( 600 ) )


If you want to control how and where it is cahced, then you have additional options to set the
'cacheability'. Sometimes those network and user caches can cause you real troubles. So we get to use this:


Response
.Cache.SetCacheability( HttpCacheability.[option] )

The options are:

  1. NoCache  The entire page or specified fields are not cached.
  2. Server  The page is cached on the web server.
  3. Public  Client machine or shared public cache (proxy server, etc).
  4. Private  Client machine only.

 

Data Caching

This is the long pole in the tent, so I am providing a link to the gurus in the sky at Microsoft.

However, there are different ways to expire an item in the data cache. We do this, by creating dependencies.

What is a dependency?

When we insert an item to the cache, we can set the expiration policy of the item based on other resources such as physical file (s) in the server, another item or set of items in the cache, or the amount of time that has elapsed since the page was cached. Any change to those items that our cached item depends on, will force our cached item to expire.

There are three types of dependencies:

bulletFile based dependency
bulletKey based dependency
bulletTime based dependency

 

 

Have fun and enjoy your new found speed!