Table of Contents

Class MemoryCache<TKey, TEntry>

Namespace
LinqToDB.Common.Internal.Cache
Assembly
linq2db.dll

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 MemoryCacheOptions

The options of the cache.

Properties

Count

Gets the count of the current entries for diagnostic purposes.

public int Count { get; }

Property Value

int

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 TKey

An 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 TKey

An 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 TKey

An object identifying the requested entry.

value TEntry

The located value or null.

Returns

bool

True if the key was found.