Sdílet prostřednictvím


MemoryCache Class

Definition

An implementation of IMemoryCache using a dictionary to store its entries.

public ref class MemoryCache : IDisposable, Microsoft::Extensions::Caching::Memory::IMemoryCache
public class MemoryCache : IDisposable, Microsoft.Extensions.Caching.Memory.IMemoryCache
type MemoryCache = class
    interface IMemoryCache
    interface IDisposable
Public Class MemoryCache
Implements IDisposable, IMemoryCache
Inheritance
MemoryCache
Implements

Constructors

MemoryCache(IOptions<MemoryCacheOptions>, ILoggerFactory)

Creates a new MemoryCache instance.

MemoryCache(IOptions<MemoryCacheOptions>)

Creates a new MemoryCache instance.

Properties

Count

Gets the count of the current entries for diagnostic purposes.

Keys

Gets an enumerable of the all the keys in the MemoryCache.

Methods

Clear()

Removes all keys and values from the cache.

Compact(Double)
CreateEntry(Object)

Creates or overwrites an entry in the cache.

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

Dispose(Boolean)

Disposes the cache and clears all entries.

Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
Finalize()

Cleans up the background collection events.

GetCurrentStatistics()

Gets a snapshot of the current statistics for the memory cache.

GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
Remove(Object)

Removes the object associated with the given key.

ToString()

Returns a string that represents the current object.

(Inherited from Object)
TryGetValue(Object, Object)

Gets the item associated with this key if present.

Extension Methods

Get(IMemoryCache, Object)

Gets the value associated with this key if present.

Get<TItem>(IMemoryCache, Object)

Gets the value associated with this key if present.

GetOrCreate<TItem>(IMemoryCache, Object, Func<ICacheEntry,TItem>, MemoryCacheEntryOptions)

Gets the value associated with this key if it exists, or generates a new entry using the provided key and a value from the given factory if the key is not found.

GetOrCreate<TItem>(IMemoryCache, Object, Func<ICacheEntry,TItem>)

Gets the value associated with this key if it exists, or generates a new entry using the provided key and a value from the given factory if the key is not found.

GetOrCreateAsync<TItem>(IMemoryCache, Object, Func<ICacheEntry,Task<TItem>>, MemoryCacheEntryOptions)

Asynchronously gets the value associated with this key if it exists, or generates a new entry using the provided key and a value from the given factory if the key is not found.

GetOrCreateAsync<TItem>(IMemoryCache, Object, Func<ICacheEntry,Task<TItem>>)

Asynchronously gets the value associated with this key if it exists, or generates a new entry using the provided key and a value from the given factory if the key is not found.

Set<TItem>(IMemoryCache, Object, TItem, MemoryCacheEntryOptions)

Sets a cache entry with the given key and value and apply the values of an existing MemoryCacheEntryOptions to the created entry.

Set<TItem>(IMemoryCache, Object, TItem, IChangeToken)

Sets a cache entry with the given key and value that will expire when IChangeToken expires.

Set<TItem>(IMemoryCache, Object, TItem, DateTimeOffset)

Sets a cache entry with the given key and value that will expire in the given duration.

Set<TItem>(IMemoryCache, Object, TItem, TimeSpan)

Sets a cache entry with the given key and value that will expire in the given duration from now.

Set<TItem>(IMemoryCache, Object, TItem)

Associate a value with a key in the IMemoryCache.

TryGetValue<TItem>(IMemoryCache, Object, TItem)

Tries to get the value associated with the given key.

Applies to