MemoryCache.Dispose Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Releases all resources that are used by the current instance of the MemoryCache class.
public:
virtual void Dispose();
public void Dispose ();
abstract member Dispose : unit -> unit
override this.Dispose : unit -> unit
Public Sub Dispose ()
Implements
Remarks
Each MemoryCache instance is bound to the AppDomainUnloaded event. However, during application-domain shutdown, if a memory-based cache has not been explicitly disposed, the cache instance will automatically call the Dispose method.
The disposed cache instance is shut down using the following steps:
The state of the cache is set to indicate that the cache is disposed. Any attempt to call public caching methods that change the state of the cache, such as methods that add, remove, or retrieve cache entries, might cause unexpected behavior. For example, if you call the Set method after the cache is disposed, a no-op error occurs. If you attempt to retrieve items from the cache, the Get method will always return
null
.Performance counter information is no longer raised from the current cache instance.
All references to cached objects held by the current cache instance are released.
Any CacheEntryChangeMonitor instances that are currently monitoring entries in the cache are notified.
Callback objects that provide notification of changes for those monitors are called.
Any CacheItemRemovedCallback instances that are registered with entries in the cache are called. The removal reason that is passed to the callbacks is CacheSpecificEviction.
Applies to
反馈
https://aka.ms/ContentUserFeedback。
即将发布:在整个 2024 年,我们将逐步淘汰作为内容反馈机制的“GitHub 问题”,并将其取代为新的反馈系统。 有关详细信息,请参阅:提交和查看相关反馈