Open sandboxFocus

Method GetFromCacheOrExecuteTaskAsync

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.

Declaration
public Task<TTaskResultType?> GetFromCacheOrExecuteTaskAsync<TTaskResultType>(CachedMethodMetadata? metadata, object? instance, object?[] args, Func<object?, object?[], CancellationToken, Task<object?>> func, CacheItemConfiguration? configuration = null, CancellationToken cancellationToken = default)
Parameters
Type Name Description
CachedMethodMetadata metadata

Metadata about the cached method, or null if the cache registration has not been initialized yet (e.g., when a cached method is called from a static field initializer). When null, caching is bypassed and the original method is called directly.

object instance

The instance on which the method is called, or null for static methods.

object[] args

The method arguments.

Func<object, object[], CancellationToken, Task<object>> func

A delegate that invokes the original method if the value is not in cache.

CacheItemConfiguration configuration

Optional configuration overriding the default settings.

CancellationToken cancellationToken

A cancellation token.

Returns
Type Description
Task<TTaskResultType>

A task representing the cached or computed result.

Type Parameters
Name Description
TTaskResultType

The type of the task result.

Implements