Home arrow ASP.NET arrow Page 4 - How Caching Means More Ca-ching, Part 2

How Caching Means More Ca-ching, Part 2

I've introduced you to Output caching and Fragment caching in my last article. By means of both we are able to increase the performance of our web applications significantly by storing and retrieving commonly accessed pages and fragments of pages in memory. This article will explain the use of the third and most granular cache method, Data Caching. I will show you how to cache at the object level. Translation: more flexibility, more speed. Therefore, happier users, and not to mention (cough cough), more ca-ching.

Author Info:
By: Justin Cook
Rating: 4 stars4 stars4 stars4 stars4 stars / 66
April 27, 2004
  1. · How Caching Means More Ca-ching, Part 2
  2. · Methods
  3. · You're Too Old, Please Leave
  4. · Learn to Set Priorities!

print this article

How Caching Means More Ca-ching, Part 2 - Learn to Set Priorities!
(Page 4 of 4 )

If you accomplish your goal of becoming an advanced developer, and build wonderful applications to which people will instinctively flock like the salmon of Capistrano, you'll inevitably come up against certain limitations. One such limitation is the amount of available memory on the Web Server, generally something over which you have little control.

When this does happen (which it will), ASP.NET will try to shed some weight. It does this by purging cached items, which could present a problem if it were indiscriminately throwing items away, and something critical gets tossed. Naturally, Microsoft foresaw this situation, and graciously allowed us to set the Priority, or preferred purging order, of cached objects. Here are the different priority settings we have available:

  • NotRemovable Never removed on low memory purging. Be careful with this one!

  • High last purged

  • AboveNormal less likely purged

  • Normal default

  • BelowNormal more likely purged

  • Low first purged

Before I show you the code to implement this, I have to inform you that there are yet another two options that absolutely must be included if you wish to set cache priorities. The first is the CacheItemPriorityDecay setting, which decays (decreases) the priority as the object is less frequently accessed. It can be set to Never, Slow, Medium, or Fast.

The last option that must be set is the CacheItemRemoveCallback, which sets when the application is notified of the purging of a cached item. The possible settings are DependencyChanged, Expired, Removed, or Underused.

Here is the final example, showing all the options I've gone through:

strVal "Finally, we're done!"
.fromseconds(60), CacheItemPriority.BelowNormal_
and Cons of Data Caching 

To sum it all up, I'd like to just give a quick runs down of both the positive and negative aspects of Data caching.

On the positive side: if a page is too dynamic for either Output or Fragment caching, Data caching will provide the flexibility and performance enhancements that you require. Also, if you have very commonly accessed objects that may be used on several pages throughout your application, you could throw them in the cache so that they could be almost instantly delivered to each page from memory. And the biggest advantage I see is in the case of large or slow-loading objects. You can load them right into cache the first time they're requested, and continue to serve them from memory. This could be great for collections of data pulled from a database, such as an employee list, or a site navigation structure that you don't want to have to hit the database for on every page load.

So then, what are the negative aspects, the cons? Hmm, I would have to say that once you become adept at employing the various cache engines within your application, people will be too happy with you as a programmer, you will be far too much in demand, and your fame and pay-check will swell so greatly that you will be at risk of losing touch with reality. (Please write me if that happens to you.)

DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

blog comments powered by Disqus

- How Caching Means More Ca-ching, Part 2
- How Caching Means More Ca-ching, Part 1
- Reading a Delimited File Using ASP.Net and V...
- What is .Net and Where is ASP.NET?
- An Object Driven Interface with .Net
- Create Your Own Guestbook In ASP.NET
- HTTP File Download Without User Interaction ...
- Dynamically Using Methods in ASP.NET
- Changing the Page Size Interactively in a Da...
- XML Serialization in ASP.NET
- Using Objects in ASP.NET: Part 1/2
- IE Web Controls in VB.NET
- Class Frameworks in VB .NET
- Cryptographic Objects in C#: Part 1
- Sample Chapter: Pure ASP.Net

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2019 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials