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

-或-

中的CacheDependency对象dependenciesnull.

CacheDependency从多个Cache条目引用对象。

示例

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

         ' 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)

适用于