Open sandboxFocus

Class MemoryCachingBackend

A CachingBackend based on System.Runtime.Caching.MemoryCache (MemoryCache). This cache is part of .NET Framework and is available for .NET Standard in the NuGet package System.Runtime.Caching.

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

To use this backend, assign an instance to DefaultBackend before the first call to a cached method. By default, it stores items in Default; pass another MemoryCache to the constructor to isolate the cached items. This backend supports cache dependencies.

Each process has its own in-memory cache. When several instances of an application run at the same time, wrap this backend in a cache invalidator, such as RedisCacheInvalidator or AzureServiceBusCacheInvalidator, so that an invalidation in one instance is propagated to the others.

Constructors

Name Description
MemoryCachingBackend()

Initializes a new instance of the MemoryCachingBackend class based on the Default instance of the MemoryCache class.

MemoryCachingBackend(MemoryCache)

Initializes a new instance of the MemoryCachingBackend class based on the given MemoryCache.

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.

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.

WhenBackgroundTasksCompleted(CancellationToken)

Returns a Task that is signaled to the complete state when all background tasks have completed.

See Also