What are the advantages and disadvantages of ASP.NET Caching?
“Caching is one of the best and often easiest ways to improve the performance of an application” (Spaanjaars ). Although accessing data is quicker, many developers too often overlook its usefulness which can be quite advantageous. For instance, caching allows a copy of your data to be stored in a location so that it can be fetched from the original source when needed instead of regenerating the data again. To make it easier, many caching solutions enable data to be stored in memory which is usually the fastest way to access data. The .NET cache does this by allowing you to store frequently accessed data in a special location within the computer’s memory. So clearly, its advantages are improved responsiveness and performance of your application.
Although caching greatly improves your application, there are some common pitfalls with caching data. Sometimes when working with caching you will find that you will end up with stale or out of date data. This means that the data you are working with no longer matches the source from which it derived. To avoid this, cache invalidation needs to occur. Cache invalidation removes an item from the cache to allow re-creation during the next request.
Another pitfall is a developer will assume an item is present in the cache although it is not. The ASP.NET application will automatically remove infrequently used items from the cache ever so often to minimize memory consumption. So it is not wise to assume that the item will always be there.
Spaanjaars, Imar. Beginning ASP.NET IN C# AND VB. Indianapolis, IN: Wiley Publishing, Inc., 2010.