共用方式為


AggregateCacheDependency 類別

定義

結合儲存於 ASP.NET 應用程式之 Cache 物件中的項目和 CacheDependency 物件的陣列之間的多個相依性。 此類別無法獲得繼承。

public ref class AggregateCacheDependency sealed : System::Web::Caching::CacheDependency
public sealed class AggregateCacheDependency : System.Web.Caching.CacheDependency
type AggregateCacheDependency = class
    inherit CacheDependency
Public NotInheritable Class AggregateCacheDependency
Inherits CacheDependency
繼承
AggregateCacheDependency

範例

下列程式碼範例會 AggregateCacheDependency 使用 類別,將 名為 XMLDataSet 的 新增 DataSet 至相依于文字檔和 XML 檔案的快取。

   ' When the page is loaded, use the 
   ' AggregateCacheDependency class to make 
   ' a cached item dependent on two files.
   
   Sub Page_Load(sender As Object, e As EventArgs)
      Dim Source As DataView
   
      Source = Cache("XMLDataSet")
   
      If Source Is Nothing
             Dim DS As New DataSet
             Dim FS As FileStream
             Dim Reader As StreamReader
             Dim txtDep As CacheDependency
             Dim xmlDep As CacheDependency
             Dim aggDep As AggregateCacheDependency
   
   
             FS = New FileStream(Server.MapPath("authors.xml"),FileMode.Open,FileAccess.Read)
             Reader = New StreamReader(FS)
             DS.ReadXml(Reader)
             FS.Close()
   
             Source = new DataView(ds.Tables(0))
            ' 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)
             If aggDep.HasChanged = True Then
                chngMsg.Text = "The dependency changed at: " & DateTime.Now
   
             Else
                chngMsg.Text = "The dependency changed last at: " & aggDep.UtcLastModified.ToString()
             End If

   
             cacheMsg1.Text = "Dataset created explicitly"
           Else
             cacheMsg1.Text = "Dataset retrieved from cache"
           End If
   
   
             MyLiteral.Text = Source.Table.TableName
             MyDataGrid.DataSource = Source
             MyDataGrid.DataBind()
         End Sub
 

         Public Sub btn_Click(sender As Object, e As EventArgs )
   
          If (MyTextBox.Text = String.Empty) Then
             msg2.Text ="You have not changed the text file."
          Else
             msg2.Text="You added " & MyTextBox.Text & "."
   
             ' Create an instance of the StreamWriter class
             ' to write text to a file.
             Dim sw As StreamWriter
             sw = File.CreateText(Server.MapPath("Storage.txt"))
   
             ' Add some text to the file.
             sw.Write("You entered:")
             sw.WriteLine(MyTextBox.Text)
   
             ' Write arbitrary objects to the file as needed.
             sw.Write("Text added at:")
             sw.WriteLine(DateTime.Now)
             sw.WriteLine("-------------------")
             sw.Close()
          End If
        End Sub

備註

類別 AggregateCacheDependency 會監視相依性物件的集合,以便在其中任何一個變更時自動移除快取的專案。 陣列中的物件可以是 CacheDependency 物件、 SqlCacheDependency 物件、衍生自 CacheDependency 的自訂物件,或這些物件的任何組合。

類別 AggregateCacheDependencyCacheDependency 類別不同,其可讓您將不同類型的多個相依性與單一快取專案產生關聯。 例如,如果您建立一個從SQL Server資料庫資料表和 XML 檔案匯入資料的頁面,您可以建立 SqlCacheDependency 物件來代表資料庫資料表的相依性,以及 CacheDependency 表示 XML 檔案的相依性。 Cache.Insert您可以建立類別的 AggregateCacheDependency 實例,並將每個相依性新增至該相依性,而不是為每個相依性呼叫。 然後,您可以使用單 Insert 一呼叫讓頁面相依于 AggregateCacheDependency 實例。

建構函式

AggregateCacheDependency()

初始化 AggregateCacheDependency 類別的新執行個體。

屬性

HasChanged

取得值,指出 CacheDependency 是否已經變更。

(繼承來源 CacheDependency)
UtcLastModified

取得上次變更相依性的時間。

(繼承來源 CacheDependency)

方法

Add(CacheDependency[])

CacheDependency 物件陣列新增至 AggregateCacheDependency 物件。

DependencyDispose()

釋放由 CacheDependency 類別及任何衍生自 CacheDependency 的類別所使用的資源。

(繼承來源 CacheDependency)
Dispose()

釋放 CacheDependency 物件所使用的資源。

(繼承來源 CacheDependency)
Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
FinishInit()

完成 CacheDependency 物件的初始化。

(繼承來源 CacheDependency)
GetFileDependencies()

取得檔案相依性。

GetFileDependencies()

取得檔案相依性。

(繼承來源 CacheDependency)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
GetUniqueID()

擷取 AggregateCacheDependency 物件的唯一識別碼。

ItemRemoved()

已在移除受監視的快取項目時呼叫。

(繼承來源 CacheDependency)
KeepDependenciesAlive()

針對相依於這個項目的每個快取項目,更新上次存取時間。

(繼承來源 CacheDependency)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
NotifyDependencyChanged(Object, EventArgs)

告知基底 CacheDependency 物件,由衍生的 CacheDependency 類別所表示的相依性已經變更。

(繼承來源 CacheDependency)
SetCacheDependencyChanged(Action<Object,EventArgs>)

加入 Action 方法來處理在變更此相依性時通知有興趣的對象。

(繼承來源 CacheDependency)
SetUtcLastModified(DateTime)

標記上次變更相依性的時間。

(繼承來源 CacheDependency)
TakeOwnership()

允許第一位使用者宣告這個相依性的獨佔擁有權。

(繼承來源 CacheDependency)
ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

適用於