AggregateCacheDependency.Add(CacheDependency[]) 方法

定义

CacheDependency 对象添加 AggregateCacheDependency 对象的数组。

public:
 void Add(... cli::array <System::Web::Caching::CacheDependency ^> ^ dependencies);
public void Add (params System.Web.Caching.CacheDependency[] dependencies);
member this.Add : System.Web.Caching.CacheDependency[] -> unit
Public Sub Add (ParamArray dependencies As CacheDependency())

参数

dependencies
CacheDependency[]

要添加的 CacheDependency 对象的数组。

例外

dependenciesnull

- 或 -

dependencies 中的 CacheDependency 对象为 null

从多个 CacheDependency 项引用 Cache 对象。

示例

下面的代码示例将 Add 方法与AggregateCacheDependency构造函数结合使用来创建两CacheDependency个对象,将它们添加到名为 的myDepArray数组中,然后使缓存中的项依赖于这两个CacheDependencyCacheDependency对象。

         ' Create two CacheDependency objects, one to a
         ' text file and the other to an XML file. 
         ' Create a CacheDependency array with these 
         ' two objects as items in the array.
          txtDep = New CacheDependency(Server.MapPath("Storage.txt"))
          xmlDep = New CacheDependency(Server.MapPath("authors.xml"))
          Dim DepArray() As CacheDependency = {txtDep, xmlDep}

          ' Create an AggregateCacheDependency object and 
          ' use the Add method to add the array to it.   
          aggDep = New AggregateCacheDependency()
          aggDep.Add(DepArray)

          ' Call the GetUniqueId method to generate
          ' an ID for each dependency in the array.
          msg1.Text = aggDep.GetUniqueId()
          
          ' Add the new data set to the cache with 
          ' dependencies on both files in the array.
          Cache.Insert("XMLDataSet", Source, aggDep)

适用于