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
TKeyTEntry
- 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
optionsAccessorMemoryCacheOptionsThe 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
percentagedouble
CreateEntry(TKey)
Create or overwrite an entry in the cache.
public ICacheEntry<TKey, TEntry> CreateEntry(TKey key)
Parameters
keyTKeyAn 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
disposingbool
~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
keyTKeyAn 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
keyTKeyAn object identifying the requested entry.
valueTEntryThe located value or null.
Returns
- bool
True if the key was found.