Gil Fink on .Net

Fink about IT

News

Microsoft MVP

MCPD Enterprise Applications Developer

Gil Fink

My Linkedin profile

Locations of visitors to this page

Creative Commons License

Blog Roll

Hebrew MSDN Articles

Index Pages

My OSS Projects

Improving Performance By Using ASP.NET Caching

Improving Performance By Using ASP.NET Caching

What is ASP.NET caching mechanism?
When to use caching? andASP.NET Caching how can I use it in
order to improve my site performance? are the
questions this post series is going to answer.

Introduction
The caching mechanism is one of the most powerful feature shipped with ASP.NET.
Even so, most developers don’t understand its power and misuse it. I had the
opportunity to see and to hear about a lot of developer mistakes in the area of bad
caching implementation or in the other hand not using caching mechanism when
appropriate.

What is ASP.NET Caching?
The caching mechanism was made to store frequently accessed data in memory for a
fast retrieval latter. When the data is stored in memory it can be retrieved faster then
in all other storage mechanisms and therefore can boost performance. For example if
I have an XML file that holds application relevant data I can read it once and cache
the data. When I cache the data I won’t need to use another I/O operations of reading
the file in order to use the data again. The data will be available in memory and will be
retrieved faster. This is one example of how to use cache but the thing you need to
ask yourself now is what if I make an update to the file? how the cache mechanism will
know that? these questions are good but the ASP.NET caching can handle those things
and what you need to understand is how to tell it to do so.

ASP.NET Caching Types
ASP.NET
provide two types of caching:

  • Application caching – A key value collection that stores the objects in memory
    and manage the objects lifetime in memory automatically.
  • Page output cache – A mechanism to cache whole pages or part of them in order
    to save time and resources in rendering them again in future requests.

Summary
The post introduced the ASP.NET caching concept and described the types of caching in
general. The following posts in the series will get into more details about how and
what to do in order improve performance by using caching.

Comments

alikl said:

Gil!

Great topic to cover - looking forward to more like these.

You also might want to tag it with "Performance" tag

thanks

# August 9, 2008 4:01 PM

DotNetKicks.com said:

You've been kicked (a good thing) - Trackback from DotNetKicks.com

# August 9, 2008 4:10 PM

Roberto said:

Description of the topic is fine but some code examples are always useful.

# August 10, 2008 1:21 AM

Rotem Bloom said:

There are some Considerations you have to take if you want to work with Page output cache like:

1) Browsers cache content based on the URL. When the URL changes, the browser fetches a new version from origin server

2) Store cached content under a common folder. For example, store all images of your site under the /static folder instead of storing images separately under different subfolders.

3) You can use query string to differentiate versions of same file. For example, a GIF can be accessed with a dummy query string like /images/mygif.gif?v=1.

4) Any content that is served over SSL is not cached.

5) Cache only happens for HTTP GET requests. HTTP POST requests are never cached.

5) You can also configure Static Content Caching in IIS.

# August 10, 2008 1:58 AM

Gil Fink said:

Thanks Alik,

I hope to keep up for the expectations :-). Also, the point was taken and I added a performance tag :-).

# August 10, 2008 2:02 AM

Gil Fink said:

Hi Roberto,

In the following posts in this series I'm going to explain the topic in details and add code examples. This post was only the introduction to the topic. Even so, you made a good point that was taken for other series.

# August 10, 2008 2:05 AM

Gil Fink said:

Thanks Rotem,

The things you wrote are correct and should be considered. The current post is only an introduction to the caching series and I'm going to cover output cache in another post in the near future. Stay toned to the next post :-)

# August 10, 2008 2:32 AM

Rotem Bloom said:

No problem Gil. I also add your blog to my favorite links on my blog because I really enjoy reading your blog :-)

# August 10, 2008 4:12 AM

Gil Fink said:

It an honor Rotem. Thanks :-)

# August 11, 2008 2:15 PM

Subbu Allamaraju said:

Regarding Rotem Boom's comment above

> 5) Cache only happens for HTTP GET requests. HTTP POST requests are never cached.

This is incorrect. POST responses can be cached as long as the response includes freshness headers (such Last-Modified, Expires etc.)

# October 12, 2008 10:09 PM

Gil Fink said:

Hi Subbu Allamaraju,

Thanks for the correction you made. VaryByParams of the output cache for example allows you to specify the HTTP GET or HTTP POST parameters to vary the cache entries.

# October 13, 2008 3:47 AM