ASP.NET 2.0 Performance Inspection Questions - Caching

From Guidance Share

Jump to: navigation, search

- J.D. Meier, Srinath Vasireddy, Ashish Babbar, Rico Mariani, and Alex Mackman


Do you have too many variations for output caching?

Check your pages that use the output cache to ensure that the number of variations has a limit. Too many variations of an output cached page can cause an increase in memory usage. You can identify pages that use the output cache by searching for the string "OutputCache."

Could you use output caching?

When reviewing your pages, start by asking yourself if the whole page can be cached. If the whole page cannot be cached, can portions of it be cached? Consider using the output cache even if the data is not static. If your content does not need to be delivered in near real-time, consider output caching. Using the output cache to cache either the entire page or portions of the page can significantly improve performance.

Is there static data that would be better stored in the cache? Identify application-side data that is static or infrequently updated. This type of data is a great candidate for storing in the cache.

Do you check for nulls before accessing cache items?

You can improve performance by checking for null before accessing the cached item as shown in the following code fragment.

  Object item = Cache["myitem"];
  if (item==null)
    // repopulate the cache

This helps avoid any exceptions which are caused by null objects. To find where in your code you access the cache, you can search for the string "Cache."

Related Items

For more information about the questions and issues raised in this section, see ASP.NET 2.0 Performance Guidelines - Caching.

Personal tools