Pages

Wednesday, 24 October 2012

Define Dependencies Between Cached Items

  • To add an item that has a dependency on a file to the cache
  1. You can add an item with a dependency to the cache by using the dependencies parameter in the Cache.Add or Cache.Insert method. The following example demonstrates using the Insert method to add an item with a dependency on an XML file to the cache:                           
    Visual basic
     
         Cache.Insert("MyData1", connectionString, new CacheDependency(Server.MapPath
("~\myConfig.xml")))
          C#
         Cache.Insert("MyData1", connectionString, new CacheDependency(Server.MapPath
("~\myConfig.xml")));
  • To add an item that has a dependency on another cache item to the cache
  1. You can also add an item that depends on another object in the cache to the cache,as shown in the following example:
       Visual Basic 
         Dim sDependencies As String(1)
         sDependencies(0) = "OriginalItem"
        Dim dependency As CacheDependency = New CacheDependency(Nothing, sDependencies)
        Cache.Insert("DependentItem", "This item depends on OriginalItem", dependency)
      C#
         string[] sDependencies = new string[1];
         sDependencies(0) = "OriginalItem";
         CacheDependency dependency = new CacheDependency(null, sDependencies);
        Cache.Insert("DependentItem", "This item depends on OriginalItem", dependency);