Open sandboxFocus

Interface ICachingService

Front-end interface used by the caching aspects and for imperative cache invalidation.

Namespace: Metalama.Patterns.Caching
Assembly: Metalama.Patterns.Caching.dll
Syntax
public interface ICachingService : IAsyncDisposable, IDisposable
Remarks

This interface is the primary entry point for interacting with the caching system at run time. It is consumed by the CacheAttribute aspect and provides imperative methods for cache invalidation through the CachingServiceExtensions extension methods.

Instances are obtained either through dependency injection (when configured via AddMetalamaCaching(IServiceCollection, Action<ICachingServiceBuilder>?)) or through the Default static property (when dependency injection is disabled).

Properties

Name Description
AllBackends

Gets the collection of all CachingBackend instances used by this service across all profiles.

KeyBuilder

Gets the ICacheKeyBuilder used to generate cache keys from method arguments.

Logger

Gets the FlashtraceSource used for logging caching operations.

Methods

Name Description
GetFromCacheOrExecuteTaskAsync<TTaskResultType>(CachedMethodMetadata, object?, object?[], Func<object?, object?[], CancellationToken, Task<object?>>, CacheItemConfiguration?, CancellationToken)

Gets a value from the cache or executes an asynchronous method returning Task<TResult> and caches the result. This method is called by the generated code of the CacheAttribute aspect.

GetFromCacheOrExecuteValueTaskAsync<TTaskResultType>(CachedMethodMetadata, object?, object?[], Func<object?, object?[], CancellationToken, ValueTask<object?>>, CacheItemConfiguration?, CancellationToken)

Gets a value from the cache or executes an asynchronous method returning ValueTask<TResult> and caches the result. This method is called by the generated code of the CacheAttribute aspect.

GetFromCacheOrExecute<TResult>(CachedMethodMetadata, object?, object?[], Func<object?, object?[], object?>, CacheItemConfiguration?, CancellationToken)

Gets a value from the cache or executes a synchronous method and caches the result. This method is called by the generated code of the CacheAttribute aspect.

InitializeAsync(CancellationToken)

Initializes the caching service. It is recommended to call this method from the start-up program sequence when the back-end involves a network or out-of-process service (e.g. Redis, Azure). If this method is not called, initialization will occur automatically upon the first call any cached method.

Extension Methods

See Also