語言

CacheDependency.GetUniqueID 方法

定義

取得物件的唯一識別碼 CacheDependency 。

public:
 virtual System::String ^ GetUniqueID();
public virtual string GetUniqueID();
abstract member GetUniqueID : unit -> string
override this.GetUniqueID : unit -> string
Public Overridable Function GetUniqueID () As String

傳回

物件的唯一識別碼 CacheDependency 。

範例

以下程式碼範例建立一個 AggregateCacheDependency 名為 aggDep的物件,其陣列中有兩個 CacheDependency 物件。 一旦 aggDep 實例化,程式碼會呼叫該 GetUniqueID 方法,為兩個相依產生唯一識別碼,該識別碼包含 aggDep 並顯示包含該頁面的識別碼。 然後將一個項目加入 Cache,使用 Insert 該方法,作為 aggDep 依賴關係。

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

備註

此方法特別適合追蹤與某項目或應用程式相關的多個類別實例 CacheDependency 。

識別碼是檔案名稱(檔案相依)或金鑰名稱(快取金鑰相依)以及此方法指派給相依的字串的組合。 在源自該 CacheDependency 類別的類別中,你可以覆寫此方法,自訂其產生唯一識別碼的方式。

適用於

另請參閱