Your application draws on data that is expensive to create from a performance perspective, so you want to store it in memory, where it can be accessed by users throughout the lifetime of the application. The problem is that the data changes occasionally and you need to refresh the data when it changes.
Place the data in the
Cache object with a
dependency set to the source of the data so
the data will be reloaded when it changes. Example 13-3 and Example 13-4 show the code
we’ve written to demonstrate this solution. In this
case, these are VB and C# code-behind files for
Global.asax that place some sample XML book data
Cache object. In our example, the book data
is automatically removed from the cache anytime the XML file is
Cache object in ASP.NET provides the ability
to store application data in a manner similar to the storing of data
Application object. The
Cache object, unlike the
Application object, lets you specify that the
cached data is to be replaced at a specified time or whenever there
is a change to the original source of the data.
In Example 13-3 and Example 13-4, two methods have been added to
global.asax.cs for C#). The first method
getBookData) provides access to the data stored
Cache object with the appropriate checking
(to ensure the data is still valid) and reloading as required. The
getBookData method performs the following
Gets a reference to ...