The ASP.NET Cache Object
In "classic" ASP many developers used the Application object as a cache. They stuck everything from single variables to the whole files in there, and when they updated the information, they then forced a refresh of the entire Web application to update the Application object. Not only was this like a using a sledgehammer to crack a nut, it was a memory intensive way of doing thing and the more junk that was accumulated in the application object, the more sluggish your web server would become.
The Cache object is a large feature addition to ASP.NET and seems to have been hidden away in the documentation. Despite initially appearing daunting, there's no reason why anyone can't use it. This is a tutorial on how to add and remove items from the Cache object both implicitly and explicitly, using the dependencies or timestamp expiration policies which mean that you can force the contents of the cache to be expired and then reload them if either a specific date/time is reached, the timestamp on a file changes, or if an item inside the cache itself changes.
Table of Content:
- Creating a Cache
- Retrieving Information From the Cache
- Removing Information From The Cache
- How To Expire Information In the Cache Object
- TimeStamp Expiration
- File Dependency
- Key Dependency
- Cache Priorities
- Locking The Cache
- An example using Caching and File Dependencies
- An example using Caching and Key Dependencies