共用方式為


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)

適用於