Caching is the process of taking information that is time-instensive to collect and storing it in a location that requires less time to access. For example, in your office your desk serves as a cache of sorts - it's much quicker to work with documents on your desk than to have to walk over to the filing cabinet each time you need a new document.
In the ASP-world, some time-intensive tasks include, among other things, accessing a database. It is much, much faster in an ASP page to access an in-memory variable than to retrieve the value from a database. (This is due to the time-expensive steps that must be taken to work with a database - setting up the database connection, issuing the query, retrieving the results, etc.)
We can use application-level variables as a cache to store database results. Since application variables are accessible from any ASP page they are quite a logical choice for a caching system. A real-world example of caching can be seen on the ASPMessageboard. On the home page a list of the various messageboard forums is presented along with how many posts each forum has received in the current day and since the forum's existence. This information is retrieved from a database. Rather than querying the database each time someone visits the main page, I use application variables to cache the results of the database query. I also use an application variable to record at what time I last updated the cache with database results. Once that time is greater than 15 minutes, I invalidate the cache. That is, I rerun the database query and populate the application variables with the result of the latest database query.
With this caching technique in place, database hits on the ASPMessageboard homepage only occur, at most, once every 15 minutes. Previously, a database read occurred each time someone visited the home page. So, if 500 page views occurred on the home page in a 15 minute cycle, 500 database reads would have occurred. With the caching system in place, regardless of how many folks visit the home page in a 15 minute period, there will be only one database read! This illustrates the performance benefit inherent with caching!
Some of the products that appear on this site are from companies from which QuinStreet receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. QuinStreet does not include all companies or all types of products available in the marketplace.