Open sandboxFocus

Class MemoryCacheBackend

A CachingBackend based on Microsoft.Extensions.Caching.Memory.IMemoryCache (IMemoryCache). This cache is recommended for ASP.NET Core use (as opposed to System.Runtime.Caching.MemoryCache).

Inheritance
MemoryCacheBackend
Implements
Namespace: PostSharp.Patterns.Caching.Backends
Assembly: PostSharp.Patterns.Caching.Backends.IMemoryCache.dll
Syntax
public class MemoryCacheBackend : CachingBackend, IDisposable
Remarks

This backend converts PostSharp configuration properties into ICacheEntry instances as follows:

Constructors

Name Description
MemoryCacheBackend()

Initializes a new MemoryCacheBackend based on a new instance of the MemoryCache class.

MemoryCacheBackend(IMemoryCache)

Initializes a new MemoryCacheBackend based on the given IMemoryCache.

MemoryCacheBackend(IMemoryCache, Func<CacheItem, long>)

Initializes a new MemoryCacheBackend based on the given IMemoryCache. The backend creates cache entries with size calculated by the given function.

Methods

Name Description
ClearCore()

Clears the cache. This protected method is part of the implementation API and is meant to be overridden in user code, not invoked.

ContainsDependencyCore(string)

Determines whether the cache contains a given dependency. This protected method is part of the implementation API and is meant to be overridden in user code, not invoked. Arguments are already validated by the consumer API.

ContainsItemCore(string)

Determines whether the cache contains an item of a given key. This protected method is part of the implementation API and is meant to be overridden in user code, not invoked. Arguments are already validated by the consumer API.

CreateFeatures()

Creates a CachingBackendFeatures object, which describes set of features implemented by the back-end. This method is invoked the first time the SupportedFeatures property is evaluated. The result is then cached.

DisposeAsyncCore(CancellationToken)

Asynchronously disposes the current CachingBackend. This protected method is part of the implementation API and is meant to be overridden in user code, not invoked.

DisposeCore(bool)

Synchronously disposes the current CachingBackend. This protected method is part of the implementation API and is meant to be overridden in user code, not invoked.

GetItemCore(string, bool)

Gets a cache item given its key. This protected method is part of the implementation API and is meant to be overridden in user code, not invoked. Arguments are already validated by the consumer API.

InvalidateDependencyCore(string)

Removes from the cache all items that have a specific dependency. This protected method is part of the implementation API and is meant to be overridden in user code, not invoked. Arguments are already validated by the consumer API.

RemoveItemCore(string)

Removes a cache item from the cache given its key. This protected method is part of the implementation API and is meant to be overridden in user code, not invoked. Arguments are already validated by the consumer API.

SetItemCore(string, CacheItem)

Sets a cache item. This protected method is part of the implementation API and is meant to be overridden in user code, not invoked. Arguments are already validated by the consumer API.