CacheDependency CacheDependency CacheDependency CacheDependency Class

定義

在儲存於 ASP.NET 應用程式的 Cache 物件中的項目以及檔案、快取索引鍵、這其中任一個的陣列或另一個 CacheDependency 物件之間建立相依性關係。Establishes a dependency relationship between an item stored in an ASP.NET application's Cache object and a file, cache key, an array of either, or another CacheDependency object. CacheDependency 類別會監視相依性關係,如此便能在其中任一個變更時,自動移除快取的項目。The CacheDependency class monitors the dependency relationships so that when any of them changes, the cached item will be automatically removed.

public ref class CacheDependency : IDisposable
public class CacheDependency : IDisposable
type CacheDependency = class
    interface IDisposable
Public Class CacheDependency
Implements IDisposable
繼承
CacheDependencyCacheDependencyCacheDependencyCacheDependency
衍生
實作

範例

下列程式碼範例示範如何使用HasChanged屬性來判斷是否CacheDependency自前一個要求中的項目變更CacheThe following code example demonstrates using the HasChanged property to determine whether a CacheDependency changed since the previous request for an item in the Cache. dt傳入的值start參數設為DateTime.NowThe dt value passed in the start parameter is set to DateTime.Now.

// Insert the cache item.
CacheDependency dep = new CacheDependency(fileName, dt);
cache.Insert("key", "value", dep);

// Check whether CacheDependency.HasChanged is true.
if (dep.HasChanged)
  Response.Write("<p>The dependency has changed.");  
else Response.Write("<p>The dependency has not changed.");
' Insert the cache item.
Dim dep As New CacheDependency(fileName, dt)
myCache.Insert("key", "value", dep)

' Check whether CacheDependency.HasChanged is true.
If dep.HasChanged Then
   Response.Write("<p>The dependency has changed.")
Else
   Response.Write("<p>The dependency has not changed.")
End If 

備註

如果您新增至快取區相依於另一個物件,例如檔案或檔案,陣列的項目會自動移除相依的項目從快取的物件變更時。If you add an item to the cache that is dependent on another object, such as a file or array of files, the dependent item is automatically removed from the cache when the object changes. 例如,假設您建立DataSetXML 檔案中的資料為基礎的物件。For example, suppose you create a DataSet object based on data in an XML file. 您可以加入DataSet至快取CacheDependency物件,可讓DataSet取決於 XML 檔案。You can add the DataSet to the cache with a CacheDependency object that makes the DataSet dependent on the XML file. 如果變更的 XML 檔案,DataSet從快取中移除。If the XML file changes, the DataSet is removed from the cache.

您可以將相依的項目加入您的應用程式的快取AddCache.Insert方法。You can add items with dependencies to your application's cache with the Add and Cache.Insert methods. 您無法使用Item[String]將項目新增至快取相依性屬性。You cannot use the Item[String] property to add items to the cache with dependencies.

若要設定相依性,您建立的執行個體CacheDependency類別,指定檔案、 金鑰或目錄的項目是相依,,然後將傳遞至相依性AddCache.Insert方法。To set up a dependency, you create an instance of the CacheDependency class, specifying the files, keys, or directories on which the item is dependent, and then pass the dependency to the Add or Cache.Insert method. CacheDependency執行個體可以代表單一檔案或目錄、 檔案或目錄的陣列或陣列的檔案或目錄,以及快取索引鍵的陣列 (這些代表儲存在其他項目Cache物件)。The CacheDependency instance can represent a single file or directory, an array of files or directories, or an array of files or directories along with an array of cache keys (these represent other items stored in the Cache object).

建構函式

CacheDependency() CacheDependency() CacheDependency() CacheDependency()

初始化 CacheDependency 類別的新執行個體。Initializes a new instance of the CacheDependency class.

CacheDependency(String) CacheDependency(String) CacheDependency(String) CacheDependency(String)

初始化 CacheDependency 類別的新執行個體,這執行個體可監視檔案或目錄的變更。Initializes a new instance of the CacheDependency class that monitors a file or directory for changes.

CacheDependency(String, DateTime) CacheDependency(String, DateTime) CacheDependency(String, DateTime) CacheDependency(String, DateTime)

初始化 CacheDependency 類別的新執行個體,這執行個體可監視檔案或目錄的變更。Initializes a new instance of the CacheDependency class that monitors a file or directory for changes.

CacheDependency(String[]) CacheDependency(String[]) CacheDependency(String[]) CacheDependency(String[])

初始化 CacheDependency 類別的新執行個體,其可監視檔案或目錄之路徑陣列的變更。Initializes a new instance of the CacheDependency class that monitors an array of paths (to files or directories) for changes.

CacheDependency(String[], DateTime) CacheDependency(String[], DateTime) CacheDependency(String[], DateTime) CacheDependency(String[], DateTime)

初始化 CacheDependency 類別的新執行個體,其可監視檔案或目錄的路徑陣列之變更,並指定變更監視開始的時間。Initializes a new instance of the CacheDependency class that monitors an array of paths (to files or directories) for changes and specifies a time when change monitoring begins.

CacheDependency(String[], String[]) CacheDependency(String[], String[]) CacheDependency(String[], String[]) CacheDependency(String[], String[])

初始化 CacheDependency 類別的新執行個體,其可監視檔案或目錄的路徑陣列、快取索引鍵的陣列或這兩者的變更。Initializes a new instance of the CacheDependency class that monitors an array of paths (to files or directories), an array of cache keys, or both for changes.

CacheDependency(String[], String[], CacheDependency) CacheDependency(String[], String[], CacheDependency) CacheDependency(String[], String[], CacheDependency) CacheDependency(String[], String[], CacheDependency)

初始化 CacheDependency 類別的新執行個體,其可監視檔案或目錄的路徑陣列、快取索引鍵的陣列或這兩者的變更。Initializes a new instance of the CacheDependency class that monitors an array of paths (to files or directories), an array of cache keys, or both for changes. 它也會使本身相依於 CacheDependency 類別的個別執行個體。It also makes itself dependent upon a separate instance of the CacheDependency class.

CacheDependency(String[], String[], CacheDependency, DateTime) CacheDependency(String[], String[], CacheDependency, DateTime) CacheDependency(String[], String[], CacheDependency, DateTime) CacheDependency(String[], String[], CacheDependency, DateTime)

初始化 CacheDependency 類別的新執行個體,其可監視檔案或目錄的路徑陣列、快取索引鍵的陣列或這兩者的變更。Initializes a new instance of the CacheDependency class that monitors an array of paths (to files or directories), an array of cache keys, or both for changes. 它也會使本身相依於 CacheDependency 類別的另一個執行個體和開始監控變更的時間。It also makes itself dependent upon another instance of the CacheDependency class and a time when the change monitoring begins.

CacheDependency(String[], String[], DateTime) CacheDependency(String[], String[], DateTime) CacheDependency(String[], String[], DateTime) CacheDependency(String[], String[], DateTime)

初始化 CacheDependency 類別的新執行個體,其可監視檔案或目錄的路徑陣列、快取索引鍵的陣列或這兩者的變更。Initializes a new instance of the CacheDependency class that monitors an array of paths (to files or directories), an array of cache keys, or both for changes.

屬性

HasChanged HasChanged HasChanged HasChanged

取得值,指出 CacheDependency 是否已經變更。Gets a value indicating whether the CacheDependency object has changed.

UtcLastModified UtcLastModified UtcLastModified UtcLastModified

取得上次變更相依性的時間。Gets the time when the dependency was last changed.

方法

DependencyDispose() DependencyDispose() DependencyDispose() DependencyDispose()

釋放由 CacheDependency 類別及任何衍生自 CacheDependency 的類別所使用的資源。Releases the resources used by the CacheDependency class and any classes that derive from CacheDependency.

Dispose() Dispose() Dispose() Dispose()

釋放 CacheDependency 物件所使用的資源。Releases the resources used by the CacheDependency object.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(Inherited from Object)
FinishInit() FinishInit() FinishInit() FinishInit()

完成 CacheDependency 物件的初始化。Completes initialization of the CacheDependency object.

GetFileDependencies() GetFileDependencies() GetFileDependencies() GetFileDependencies()

取得檔案相依性。Gets the file dependencies.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(Inherited from Object)
GetUniqueID() GetUniqueID() GetUniqueID() GetUniqueID()

擷取 CacheDependency 物件的唯一識別項。Retrieves a unique identifier for a CacheDependency object.

ItemRemoved() ItemRemoved() ItemRemoved() ItemRemoved()

已在移除受監視的快取項目時呼叫。Called when a monitored cache entry is removed.

KeepDependenciesAlive() KeepDependenciesAlive() KeepDependenciesAlive() KeepDependenciesAlive()

針對相依於這個項目的每個快取項目,更新上次存取時間。Updates the last access time of every cache item that depends on this item.

MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(Inherited from Object)
NotifyDependencyChanged(Object, EventArgs) NotifyDependencyChanged(Object, EventArgs) NotifyDependencyChanged(Object, EventArgs) NotifyDependencyChanged(Object, EventArgs)

告知基底 CacheDependency 物件,由衍生的 CacheDependency 類別所表示的相依性已經變更。Notifies the base CacheDependency object that the dependency represented by a derived CacheDependency class has changed.

SetCacheDependencyChanged(Action<Object,EventArgs>) SetCacheDependencyChanged(Action<Object,EventArgs>) SetCacheDependencyChanged(Action<Object,EventArgs>) SetCacheDependencyChanged(Action<Object,EventArgs>)

加入 Action 方法來處理在變更此相依性時通知有興趣的對象。Adds an Action method to handle notifying interested party in changes to this dependency.

SetUtcLastModified(DateTime) SetUtcLastModified(DateTime) SetUtcLastModified(DateTime) SetUtcLastModified(DateTime)

標記上次變更相依性的時間。Marks the time when a dependency last changed.

TakeOwnership() TakeOwnership() TakeOwnership() TakeOwnership()

允許第一位使用者宣告這個相依性的獨佔擁有權。Allows the first user to declare exclusive ownership of this dependency.

ToString() ToString() ToString() ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(Inherited from Object)

適用於

另請參閱