Data Caching

Data caching is another feature provided by ASP.NET that can significantly increase the speed of your data access code, by not retrieving the same data repetitively. In ASP.NET, the cache is implemented using the Cache object. Because it works just like any dictionary object, it's easy to use. The following line of code will store a DataSet in the Cache object with the name “Categories”:

Cache("Categories") = dsCategories

It can be read out of the cache later with the following code:

myDataSet = Ctype(Cache("Categories"), DataSet)

To implement data caching in your Web application, first check to see if the DataSet is stored in the cache. If it is, use the cached version. Otherwise, load the DataSet data from the database and ...

Get Sams Teach Yourself ADO.NET in 24 Hours now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.