Probably the most common way to use the cache is to store database query results to avoid round-trips to a database. Accessing memory is often orders of magnitude faster than hitting the database. In addition, you sidestep issues such as limited connection resources and database contention.
While you can effectively improve the performance of your application by simply putting items in the cache, ASP.NET's caching mechanism provides facilities for putting limits on the amount of time items remain cached. You may also set up dependencies between cached items and their physical data sources so that you may be alerted when items need to be reloaded into the cache.
Tutorial 14 Quick Reference
How to access the data cache
The data cache is available as
the
Cache
property in the pagethe
Cache
property in the currentHttpContext
Insert an item in the cache
Use the indexer notation to add an object and a value to the cache
How to insert an item in the cache with a dependency
Create a
CacheDependency
object and add the object to the cache using the overloaded insert method
How to insert an item in the cache with an expiration time
Create a
DateTime
object and add the object to the cache using the overloaded insert method
How to delete an item from the cache
Call the cache's Remove method
How to be notified that an item is being removed from the cache
Include a callback delegate when inserting an item in the cache