
Loading the Cache Proactively
You can cache data proactively by retrieving all the required state for an application or a process, typically when the application or process starts, and caching it for the lifetime of the application or process.
To load the cache proactively
- Configure the cache, defining a CacheManager object with the name Loading Scenario Cache Manager. For the necessary steps, see "QuickStart Configuration" in Caching QuickStart.
- Declare a member variable of type ICacheManager to store the CacheManager object in the ProductData class.
private ICacheManager cache;
Private cache As ICacheManager
- Create the CacheManager object by adding the following code. The factory creates the CacheManager object using the name in the configuration file(when not using the Unity Integration approach).
cache = CacheFactory.GetCacheManager("Loading Scenario Cache Manager");
cache = CacheFactory.GetCacheManager("Loading Scenario Cache Manager")
- Load the entire set of data from the XML file into the cache.
List<Product> list = this.dataProvider.GetProductList();
for (int i = 0; i < list.Count; i++)
{
Product product = list[i];
cache.Add(product.ProductID, product);
}
Dim list As List(Of Product) = Me.dataProvider.GetProductList()
Dim i As Integer
For i = 0 To list.Count - 1
Dim newProduct As Product = list(i)
cache.Add(newProduct.ProductID, newProduct)
Next