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

How Caching Means More Ca-ching, Part 1


The ASP.Net platform brought forth many new features and enhancements over the former ASP platform. One of the more significant to be introduced was caching. Previously managed by third-party components, ASP.Net came packed with rich caching options, out of the box. Regardless of whether or not your application is already built and running, it can only benefit from the proper use of caching. This article will explain the various options we have, which will in turn lead to faster applications, and therefore more satisfied users, which can only be a good thing!

Author Info:
By: Justin Cook
Rating: 4 stars4 stars4 stars4 stars4 stars / 54
April 21, 2004
TABLE OF CONTENTS:
  1. · How Caching Means More Ca-ching, Part 1
  2. · Output Caching
  3. · Call The HttpCachePolicy!
  4. · Fragment Caching

print this article
SEARCH DEVARTICLES

How Caching Means More Ca-ching, Part 1 - Fragment Caching
(Page 4 of 4 )

Careful how you read this one, it's not Fraggle Rock caching, though that would be extremely cool! "Hide you cares away, worries for another day...". This is fragment caching, and the name basically explains everything about it. We are essentially breaking up pages into chunks, or fragments, and setting the cache properties of those fragments individually. This is accomplished through the use of user controls.

I'll give you an example. Suppose you've built a time-sheets application. Most of the data could be very dynamic, perhaps people entering in full and half hours on different projects throughout the day. There may however be a schedule of people assigned to various tasks that doesn't change all that often. Well, instead of querying the database for the schedule with every page load, a potential speed booster would be to place the schedule generating code into a user control, and configure the output caching within the control itself. We've already learned how to do this, just set the @OutputCache directive or use the HttpCachePolicy class within the control, it's that easy.

One quick caveat: fragment caching doesn't support the VaryByHeader or VaryByCustom attributes. The VaryByParam works the same as with output caching, and in addition we have the use of another attribute, VaryByControl. This enables us to vary the cached output, based upon the values of server controls contained within, such as a select box, or check boxes. I won't go through the process of a user control tutorial, but you should be able to find what you need in this nice article by JB Reddy.

Aside from just giving us one awesome degree of flexibility within pages to cache or not cache whichever chunks we deem necessary, there is one other very cool advantage to fragment caching. Suppose you have a fairly common user control, for example: a navigational menu system that is shared throughout most if not all pages in the application. Well, you can set the output caching on that one fragment, that one user control, and enjoy the increase in performance instantly throughout all pages. Happy now?

Conclusion

There are many advantages attained when caching is utilized properly within an application. First of all, it's easier on the server's memory resources if you determine that fragment caching is appropriate in place of output caching. It makes for faster page loading, as script processing and database querying is only needed once for the allotted cache time, and from there on in the page can be quickly, yes, very quickly served up from memory.

If you wish to see what kind of a difference can truly be achieved, build your application first. Do some benchmarking. Then implement caching. (Keep in mind that the next article will cover yet another method, but these two should get you off the ground) You should notice improvements in the range of several hundred percent faster page loads.

So why caching mean more ca-ching? Well, remember Jack (mentioned in the outset). The users find his application too slow, and it was be nothing but complaints, despite how feature-rich it was. Jack realized that the faster you can allow people to do what they have to do, the more endeared they will be to your application, so he planned and implemented caching. Praise came showering his way, as well as good recognition. I'm sure you can connect the dots as to how that eventually lead to more ca-ching.


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
ASP.NET ARTICLES

- 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 
Support 

Developer Shed Affiliates

 




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