Class MemoryCache<TKey, TEntry>
An implementation of IMemoryCache<TKey, TEntry> using a dictionary to store its entries.
public class MemoryCache<TKey, TEntry> : IMemoryCache<TKey, TEntry>, IDisposable where TKey : notnull
Type Parameters
TKey
TEntry
- Inheritance
-
MemoryCache<TKey, TEntry>
- Implements
-
IMemoryCache<TKey, TEntry>
- Extension Methods
Constructors
MemoryCache(MemoryCacheOptions)
Creates a new MemoryCache<TKey, TEntry> instance.
public MemoryCache(MemoryCacheOptions optionsAccessor)
Parameters
optionsAccessor
MemoryCacheOptionsThe options of the cache.
Properties
Count
Gets the count of the current entries for diagnostic purposes.
public int Count { get; }
Property Value
Methods
Clear()
Remove all cache entries.
public void Clear()
Compact(double)
public void Compact(double percentage)
Parameters
percentage
double
CreateEntry(TKey)
Create or overwrite an entry in the cache.
public ICacheEntry<TKey, TEntry> CreateEntry(TKey key)
Parameters
key
TKeyAn object identifying the entry.
Returns
- ICacheEntry<TKey, TEntry>
The newly created ICacheEntry<TKey, TEntity> instance.
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()
Dispose(bool)
protected virtual void Dispose(bool disposing)
Parameters
disposing
bool
~MemoryCache()
Cleans up the background collection events.
protected ~MemoryCache()
Remove(TKey)
Removes the object associated with the given key.
public void Remove(TKey key)
Parameters
key
TKeyAn object identifying the entry.
TryGetValue(TKey, out TEntry)
Gets the item associated with this key if present.
public bool TryGetValue(TKey key, out TEntry value)
Parameters
key
TKeyAn object identifying the requested entry.
value
TEntryThe located value or null.
Returns
- bool
True if the key was found.