AppSurface Search
API Reference

Caching

Type

CachePolicy

Source

Describes the expiration behavior for a cached entry. Use the static factory methods to create common configurations.

Method

Absolute

CachePolicy Absolute(TimeSpan duration)

Creates a policy that evicts the entry after a fixed duration from creation.

Parameters

  • duration
    The time after which the entry expires.

Returns

A CachePolicy with absolute expiration.

Exceptions

  • ArgumentOutOfRangeException
    Thrown when duration is not positive.
Method

AbsoluteWithStaleWhileRevalidate

CachePolicy AbsoluteWithStaleWhileRevalidate(TimeSpan freshDuration, TimeSpan staleDuration)

Creates an absolute-expiration policy that can serve stale values while one background refresh runs.

Parameters

  • freshDuration
    The duration for which the cached value is considered fresh.
  • staleDuration
    The additional duration for which the stale value can be served while revalidating.

Returns

A CachePolicy with absolute freshness and stale-while-revalidate behavior.

Exceptions

  • ArgumentOutOfRangeException
    Thrown when freshDuration or staleDuration is not positive.

Remarks

Use this factory when a caller wants a single declaration for freshDuration absolute freshness followed by a bounded staleDuration revalidation window; use Absolute(TimeSpan) followed by WithStaleWhileRevalidate(TimeSpan) when composing or modifying an existing absolute policy. During the stale window, callers can receive out-of-date data while one background refresh per key runs; refresh failures keep the stale entry available until a later access retries. The stale-while-revalidate pattern is incompatible with sliding expiration policies.

Method

WithStaleWhileRevalidate

CachePolicy WithStaleWhileRevalidate(TimeSpan duration)

Adds a bounded stale-while-revalidate window to an absolute-expiration policy.

Parameters

  • duration
    The additional duration for which the stale value can be served while revalidating.

Returns

A new policy with the same absolute freshness and the requested stale window.

Exceptions

  • ArgumentOutOfRangeException
    Thrown when duration is not positive.
  • InvalidOperationException
    Thrown when the current policy is not absolute-only.

Remarks

Stale-while-revalidate is supported only for absolute-expiration policies because sliding freshness changes on access and cannot define a stable revalidation moment.

Method

Sliding

CachePolicy Sliding(TimeSpan window)

Creates a policy that evicts the entry if it is not accessed within the given window. Each access resets the sliding timer.

Parameters

  • window
    The idle duration after which the entry expires.

Returns

A CachePolicy with sliding expiration.

Exceptions

  • ArgumentOutOfRangeException
    Thrown when window is not positive.
Method

SlidingWithAbsolute

CachePolicy SlidingWithAbsolute(TimeSpan window, TimeSpan max)

Creates a policy that slides the entry on each access but enforces an absolute ceiling. The entry is evicted when it has been idle for window , or unconditionally after max from creation, whichever comes first.

Parameters

  • window
    The sliding idle window.
  • max
    The absolute maximum lifetime.

Returns

A CachePolicy with both sliding and absolute expiration.

Exceptions

  • ArgumentOutOfRangeException
    Thrown when window or max is not positive.
  • ArgumentException
    Thrown when window is greater than or equal to max .
Property

AbsoluteExpiration

TimeSpan? AbsoluteExpiration { get; init; } Source

Gets the absolute expiration duration. The entry is evicted after this duration regardless of access patterns.

Property

SlidingExpiration

TimeSpan? SlidingExpiration { get; init; } Source

Gets the sliding expiration window. The entry is evicted if not accessed within this duration. Each access resets the timer.

Property

StaleWhileRevalidate

TimeSpan? StaleWhileRevalidate { get; init; } Source

Gets the bounded stale window used after AbsoluteExpiration elapses. During this window IMemo returns the stale value immediately and refreshes it in the background.

Type

Memo

Source

Memoizes async factory calls using IMemoryCache with automatic key generation and per-key thundering-herd protection.

Method

GetOrCreateCoreAsync

Task<TResult> GetOrCreateCoreAsync<TState, TResult>(object key, TState state, Func<TState, CancellationToken, Task<TResult>> factory, CachePolicy policy, CancellationToken cancellationToken)

Core implementation that handles cache lookup, thundering-herd synchronization, exception caching, and entry creation with the configured policy. Uses a state-passing pattern to avoid closure allocations on the hot path. key can be a ValueTuple for efficiency.

Remarks

null results from the factory are treated as valid cached values for reference types.

Method

DrainBackgroundRefreshesAsync

Task DrainBackgroundRefreshesAsync(CancellationToken cancellationToken = default)

Joins a snapshot of background refreshes already observed by completed stale reads.

Parameters

  • cancellationToken
    Cancels only this wait, without cancelling or detaching an original refresh.

Returns

A task completing after every refresh in the snapshot has reached its original terminal state.

Exceptions

  • ObjectDisposedException
    The memo has already been disposed.
  • OperationCanceledException
    The caller cancels its wait.

Remarks

A joined refresh may have failed; stale-refresh errors remain observed, and expired callers still receive their own factory failures. Stop new reads and await their accepted calls before using this method for shutdown, then dispose the memo/cache. Refreshes registered later are not in this snapshot. This method creates no timeout, changes no cache window and never supplies a successful cached value.

Method

CreateEntryOptions

MemoryCacheEntryOptions CreateEntryOptions(SemaphoreSlim keyLock)

Creates MemoryCacheEntryOptions with a post-eviction callback that removes the corresponding SemaphoreSlim from _locks to prevent unbounded growth.

Parameters

  • keyLock
    The specific semaphore instance to capture for reference-safe eviction cleanup.
Method

OnCacheEntryEvicted

void OnCacheEntryEvicted(object key, object? value, EvictionReason reason, object? state)

Post-eviction callback that cleans up the per-key semaphore from the locks dictionary. Only removes the exact semaphore instance that was captured when the cache entry was created, preserving any newer semaphore created by concurrent callers via GetOrAdd .

Method

Dispose

void Dispose()

Disposes the underlying locks.

Property

ActiveLockCount

int ActiveLockCount { get; } Source

Gets the number of per-key semaphores currently retained for in-flight or failure-cached work.

Type

CachedFailure

Source

Sentinel wrapper stored in the cache when a factory invocation fails, allowing subsequent waiters to short-circuit instead of re-invoking the factory.

Type

StaleCacheEntry

Source

Mutable wrapper used for entries that can serve stale values while a background refresh runs.

Type

IMemo

Source

Provides memoized, cache-backed access to expensive computations with automatic key generation and thundering-herd protection.

Method

GetAsync

18 overloads
Task<TResult> GetAsync<TResult>(Func<Task<TResult>> factory, CachePolicy policy, CancellationToken cancellationToken = default)

Returns a cached result or invokes factory to compute and cache it. The cache key is automatically derived from the caller file path and line number.

Type parameters

  • TResult
    The type of the cached value.

Parameters

  • factory
    The async factory to compute the value on a cache miss.
  • policy
    The cache expiration policy.
  • cancellationToken
    A token to cancel the cache lock acquisition.

Returns

The cached or freshly computed value.

Task<TResult> GetAsync<TResult>(Func<CancellationToken, Task<TResult>> factory, CachePolicy policy, CancellationToken cancellationToken = default)

Returns a cached result or invokes factory to compute and cache it. The cache key is automatically derived from the caller file path and line number. The CancellationToken is forwarded to the factory for cooperative cancellation.

Type parameters

  • TResult
    The type of the cached value.

Parameters

  • factory
    The async factory to compute the value on a cache miss. Receives a CancellationToken .
  • policy
    The cache expiration policy.
  • cancellationToken
    A token to cancel both lock acquisition and factory invocation.

Returns

The cached or freshly computed value.

Task<TResult> GetAsync<TArg, TResult>(TArg arg, Func<TArg, Task<TResult>> factory, CachePolicy policy, CancellationToken cancellationToken = default)

Returns a cached result or invokes factory to compute and cache it. The cache key is automatically derived from the caller file path, line number, and arg .

Type parameters

  • TArg
    The type of the argument.
  • TResult
    The type of the cached value.

Parameters

  • arg
    The argument passed to the factory and incorporated into the cache key.
  • factory
    The async factory to compute the value on a cache miss.
  • policy
    The cache expiration policy.
  • cancellationToken
    A token to cancel the cache lock acquisition.

Returns

The cached or freshly computed value.

Task<TResult> GetAsync<TArg, TResult>(TArg arg, Func<TArg, CancellationToken, Task<TResult>> factory, CachePolicy policy, CancellationToken cancellationToken = default)

Returns a cached result or invokes factory to compute and cache it. The cache key is automatically derived from the caller file path, line number, and arg . The CancellationToken is forwarded to the factory for cooperative cancellation.

Type parameters

  • TArg
    The type of the argument.
  • TResult
    The type of the cached value.

Parameters

  • arg
    The argument passed to the factory and incorporated into the cache key.
  • factory
    The async factory to compute the value on a cache miss. Receives a CancellationToken .
  • policy
    The cache expiration policy.
  • cancellationToken
    A token to cancel both lock acquisition and factory invocation.

Returns

The cached or freshly computed value.

Task<TResult> GetAsync<TArg1, TArg2, TResult>(TArg1 arg1, TArg2 arg2, Func<TArg1, TArg2, Task<TResult>> factory, CachePolicy policy, CancellationToken cancellationToken = default)

Returns a cached result or invokes factory to compute and cache it. The cache key is automatically derived from the caller file path, line number, and the provided arguments.

Type parameters

  • TArg1
    The type of the first argument.
  • TArg2
    The type of the second argument.
  • TResult
    The type of the cached value.

Parameters

  • arg1
    The first argument passed to the factory and incorporated into the cache key.
  • arg2
    The second argument passed to the factory and incorporated into the cache key.
  • factory
    The async factory to compute the value on a cache miss.
  • policy
    The cache expiration policy.
  • cancellationToken
    A token to cancel the cache lock acquisition.

Returns

The cached or freshly computed value.

Task<TResult> GetAsync<TArg1, TArg2, TResult>(TArg1 arg1, TArg2 arg2, Func<TArg1, TArg2, CancellationToken, Task<TResult>> factory, CachePolicy policy, CancellationToken cancellationToken = default)

Returns a cached result or invokes factory to compute and cache it. The cache key is automatically derived from the caller file path, line number, and the provided arguments. The CancellationToken is forwarded to the factory for cooperative cancellation.

Type parameters

  • TArg1
    The type of the first argument.
  • TArg2
    The type of the second argument.
  • TResult
    The type of the cached value.

Parameters

  • arg1
    The first argument passed to the factory and incorporated into the cache key.
  • arg2
    The second argument passed to the factory and incorporated into the cache key.
  • factory
    The async factory to compute the value on a cache miss. Receives a CancellationToken .
  • policy
    The cache expiration policy.
  • cancellationToken
    A token to cancel both lock acquisition and factory invocation.

Returns

The cached or freshly computed value.

Task<TResult> GetAsync<TArg1, TArg2, TArg3, TResult>(TArg1 arg1, TArg2 arg2, TArg3 arg3, Func<TArg1, TArg2, TArg3, Task<TResult>> factory, CachePolicy policy, CancellationToken cancellationToken = default)

Returns a cached result or invokes factory to compute and cache it. The cache key is automatically derived from the caller file path, line number, and the provided arguments.

Type parameters

  • TArg1
    The type of the first argument.
  • TArg2
    The type of the second argument.
  • TArg3
    The type of the third argument.
  • TResult
    The type of the cached value.

Parameters

  • arg1
    The first argument passed to the factory and incorporated into the cache key.
  • arg2
    The second argument passed to the factory and incorporated into the cache key.
  • arg3
    The third argument passed to the factory and incorporated into the cache key.
  • factory
    The async factory to compute the value on a cache miss.
  • policy
    The cache expiration policy.
  • cancellationToken
    A token to cancel the cache lock acquisition.

Returns

The cached or freshly computed value.

Task<TResult> GetAsync<TArg1, TArg2, TArg3, TResult>(TArg1 arg1, TArg2 arg2, TArg3 arg3, Func<TArg1, TArg2, TArg3, CancellationToken, Task<TResult>> factory, CachePolicy policy, CancellationToken cancellationToken = default)

Returns a cached result or invokes factory to compute and cache it. The cache key is automatically derived from the caller file path, line number, and the provided arguments. The CancellationToken is forwarded to the factory for cooperative cancellation.

Type parameters

  • TArg1
    The type of the first argument.
  • TArg2
    The type of the second argument.
  • TArg3
    The type of the third argument.
  • TResult
    The type of the cached value.

Parameters

  • arg1
    The first argument passed to the factory and incorporated into the cache key.
  • arg2
    The second argument passed to the factory and incorporated into the cache key.
  • arg3
    The third argument passed to the factory and incorporated into the cache key.
  • factory
    The async factory to compute the value on a cache miss. Receives a CancellationToken .
  • policy
    The cache expiration policy.
  • cancellationToken
    A token to cancel both lock acquisition and factory invocation.

Returns

The cached or freshly computed value.

Task<TResult> GetAsync<TArg1, TArg2, TArg3, TArg4, TResult>(TArg1 arg1, TArg2 arg2, TArg3 arg3, TArg4 arg4, Func<TArg1, TArg2, TArg3, TArg4, Task<TResult>> factory, CachePolicy policy, CancellationToken cancellationToken = default)

Returns a cached result or invokes factory to compute and cache it. The cache key is automatically derived from the caller file path, line number, and the provided arguments.

Type parameters

  • TArg1
    The type of the first argument.
  • TArg2
    The type of the second argument.
  • TArg3
    The type of the third argument.
  • TArg4
    The type of the fourth argument.
  • TResult
    The type of the cached value.

Parameters

  • arg1
    The first argument passed to the factory and incorporated into the cache key.
  • arg2
    The second argument passed to the factory and incorporated into the cache key.
  • arg3
    The third argument passed to the factory and incorporated into the cache key.
  • arg4
    The fourth argument passed to the factory and incorporated into the cache key.
  • factory
    The async factory to compute the value on a cache miss.
  • policy
    The cache expiration policy.
  • cancellationToken
    A token to cancel the cache lock acquisition.

Returns

The cached or freshly computed value.

Task<TResult> GetAsync<TArg1, TArg2, TArg3, TArg4, TResult>(TArg1 arg1, TArg2 arg2, TArg3 arg3, TArg4 arg4, Func<TArg1, TArg2, TArg3, TArg4, CancellationToken, Task<TResult>> factory, CachePolicy policy, CancellationToken cancellationToken = default)

Returns a cached result or invokes factory to compute and cache it. The cache key is automatically derived from the caller file path, line number, and the provided arguments. The CancellationToken is forwarded to the factory for cooperative cancellation.

Type parameters

  • TArg1
    The type of the first argument.
  • TArg2
    The type of the second argument.
  • TArg3
    The type of the third argument.
  • TArg4
    The type of the fourth argument.
  • TResult
    The type of the cached value.

Parameters

  • arg1
    The first argument passed to the factory and incorporated into the cache key.
  • arg2
    The second argument passed to the factory and incorporated into the cache key.
  • arg3
    The third argument passed to the factory and incorporated into the cache key.
  • arg4
    The fourth argument passed to the factory and incorporated into the cache key.
  • factory
    The async factory to compute the value on a cache miss. Receives a CancellationToken .
  • policy
    The cache expiration policy.
  • cancellationToken
    A token to cancel both lock acquisition and factory invocation.

Returns

The cached or freshly computed value.

Task<TResult> GetAsync<TArg1, TArg2, TArg3, TArg4, TArg5, TResult>(TArg1 arg1, TArg2 arg2, TArg3 arg3, TArg4 arg4, TArg5 arg5, Func<TArg1, TArg2, TArg3, TArg4, TArg5, Task<TResult>> factory, CachePolicy policy, CancellationToken cancellationToken = default)

Returns a cached result or invokes factory to compute and cache it. The cache key is automatically derived from the caller file path, line number, and the provided arguments.

Type parameters

  • TArg1
    The type of the first argument.
  • TArg2
    The type of the second argument.
  • TArg3
    The type of the third argument.
  • TArg4
    The type of the fourth argument.
  • TArg5
    The type of the fifth argument.
  • TResult
    The type of the cached value.

Parameters

  • arg1
    The first argument passed to the factory and incorporated into the cache key.
  • arg2
    The second argument passed to the factory and incorporated into the cache key.
  • arg3
    The third argument passed to the factory and incorporated into the cache key.
  • arg4
    The fourth argument passed to the factory and incorporated into the cache key.
  • arg5
    The fifth argument passed to the factory and incorporated into the cache key.
  • factory
    The async factory to compute the value on a cache miss.
  • policy
    The cache expiration policy.
  • cancellationToken
    A token to cancel the cache lock acquisition.

Returns

The cached or freshly computed value.

Task<TResult> GetAsync<TArg1, TArg2, TArg3, TArg4, TArg5, TResult>(TArg1 arg1, TArg2 arg2, TArg3 arg3, TArg4 arg4, TArg5 arg5, Func<TArg1, TArg2, TArg3, TArg4, TArg5, CancellationToken, Task<TResult>> factory, CachePolicy policy, CancellationToken cancellationToken = default)

Returns a cached result or invokes factory to compute and cache it. The cache key is automatically derived from the caller file path, line number, and the provided arguments. The CancellationToken is forwarded to the factory for cooperative cancellation.

Type parameters

  • TArg1
    The type of the first argument.
  • TArg2
    The type of the second argument.
  • TArg3
    The type of the third argument.
  • TArg4
    The type of the fourth argument.
  • TArg5
    The type of the fifth argument.
  • TResult
    The type of the cached value.

Parameters

  • arg1
    The first argument passed to the factory and incorporated into the cache key.
  • arg2
    The second argument passed to the factory and incorporated into the cache key.
  • arg3
    The third argument passed to the factory and incorporated into the cache key.
  • arg4
    The fourth argument passed to the factory and incorporated into the cache key.
  • arg5
    The fifth argument passed to the factory and incorporated into the cache key.
  • factory
    The async factory to compute the value on a cache miss. Receives a CancellationToken .
  • policy
    The cache expiration policy.
  • cancellationToken
    A token to cancel both lock acquisition and factory invocation.

Returns

The cached or freshly computed value.

Task<TResult> GetAsync<TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TResult>(TArg1 arg1, TArg2 arg2, TArg3 arg3, TArg4 arg4, TArg5 arg5, TArg6 arg6, Func<TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, Task<TResult>> factory, CachePolicy policy, CancellationToken cancellationToken = default)

Returns a cached result or invokes factory to compute and cache it. The cache key is automatically derived from the caller file path, line number, and the provided arguments.

Type parameters

  • TArg1
    The type of the first argument.
  • TArg2
    The type of the second argument.
  • TArg3
    The type of the third argument.
  • TArg4
    The type of the fourth argument.
  • TArg5
    The type of the fifth argument.
  • TArg6
    The type of the sixth argument.
  • TResult
    The type of the cached value.

Parameters

  • arg1
    The first argument passed to the factory and incorporated into the cache key.
  • arg2
    The second argument passed to the factory and incorporated into the cache key.
  • arg3
    The third argument passed to the factory and incorporated into the cache key.
  • arg4
    The fourth argument passed to the factory and incorporated into the cache key.
  • arg5
    The fifth argument passed to the factory and incorporated into the cache key.
  • arg6
    The sixth argument passed to the factory and incorporated into the cache key.
  • factory
    The async factory to compute the value on a cache miss.
  • policy
    The cache expiration policy.
  • cancellationToken
    A token to cancel the cache lock acquisition.

Returns

The cached or freshly computed value.

Task<TResult> GetAsync<TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TResult>(TArg1 arg1, TArg2 arg2, TArg3 arg3, TArg4 arg4, TArg5 arg5, TArg6 arg6, Func<TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, CancellationToken, Task<TResult>> factory, CachePolicy policy, CancellationToken cancellationToken = default)

Returns a cached result or invokes factory to compute and cache it. The cache key is automatically derived from the caller file path, line number, and the provided arguments. The CancellationToken is forwarded to the factory for cooperative cancellation.

Type parameters

  • TArg1
    The type of the first argument.
  • TArg2
    The type of the second argument.
  • TArg3
    The type of the third argument.
  • TArg4
    The type of the fourth argument.
  • TArg5
    The type of the fifth argument.
  • TArg6
    The type of the sixth argument.
  • TResult
    The type of the cached value.

Parameters

  • arg1
    The first argument passed to the factory and incorporated into the cache key.
  • arg2
    The second argument passed to the factory and incorporated into the cache key.
  • arg3
    The third argument passed to the factory and incorporated into the cache key.
  • arg4
    The fourth argument passed to the factory and incorporated into the cache key.
  • arg5
    The fifth argument passed to the factory and incorporated into the cache key.
  • arg6
    The sixth argument passed to the factory and incorporated into the cache key.
  • factory
    The async factory to compute the value on a cache miss. Receives a CancellationToken .
  • policy
    The cache expiration policy.
  • cancellationToken
    A token to cancel both lock acquisition and factory invocation.

Returns

The cached or freshly computed value.

Task<TResult> GetAsync<TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TResult>(TArg1 arg1, TArg2 arg2, TArg3 arg3, TArg4 arg4, TArg5 arg5, TArg6 arg6, TArg7 arg7, Func<TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, Task<TResult>> factory, CachePolicy policy, CancellationToken cancellationToken = default)

Returns a cached result or invokes factory to compute and cache it. The cache key is automatically derived from the caller file path, line number, and the provided arguments.

Type parameters

  • TArg1
    The type of the first argument.
  • TArg2
    The type of the second argument.
  • TArg3
    The type of the third argument.
  • TArg4
    The type of the fourth argument.
  • TArg5
    The type of the fifth argument.
  • TArg6
    The type of the sixth argument.
  • TArg7
    The type of the seventh argument.
  • TResult
    The type of the cached value.

Parameters

  • arg1
    The first argument passed to the factory and incorporated into the cache key.
  • arg2
    The second argument passed to the factory and incorporated into the cache key.
  • arg3
    The third argument passed to the factory and incorporated into the cache key.
  • arg4
    The fourth argument passed to the factory and incorporated into the cache key.
  • arg5
    The fifth argument passed to the factory and incorporated into the cache key.
  • arg6
    The sixth argument passed to the factory and incorporated into the cache key.
  • arg7
    The seventh argument passed to the factory and incorporated into the cache key.
  • factory
    The async factory to compute the value on a cache miss.
  • policy
    The cache expiration policy.
  • cancellationToken
    A token to cancel the cache lock acquisition.

Returns

The cached or freshly computed value.

Task<TResult> GetAsync<TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TResult>(TArg1 arg1, TArg2 arg2, TArg3 arg3, TArg4 arg4, TArg5 arg5, TArg6 arg6, TArg7 arg7, Func<TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, CancellationToken, Task<TResult>> factory, CachePolicy policy, CancellationToken cancellationToken = default)

Returns a cached result or invokes factory to compute and cache it. The cache key is automatically derived from the caller file path, line number, and the provided arguments. The CancellationToken is forwarded to the factory for cooperative cancellation.

Type parameters

  • TArg1
    The type of the first argument.
  • TArg2
    The type of the second argument.
  • TArg3
    The type of the third argument.
  • TArg4
    The type of the fourth argument.
  • TArg5
    The type of the fifth argument.
  • TArg6
    The type of the sixth argument.
  • TArg7
    The type of the seventh argument.
  • TResult
    The type of the cached value.

Parameters

  • arg1
    The first argument passed to the factory and incorporated into the cache key.
  • arg2
    The second argument passed to the factory and incorporated into the cache key.
  • arg3
    The third argument passed to the factory and incorporated into the cache key.
  • arg4
    The fourth argument passed to the factory and incorporated into the cache key.
  • arg5
    The fifth argument passed to the factory and incorporated into the cache key.
  • arg6
    The sixth argument passed to the factory and incorporated into the cache key.
  • arg7
    The seventh argument passed to the factory and incorporated into the cache key.
  • factory
    The async factory to compute the value on a cache miss. Receives a CancellationToken .
  • policy
    The cache expiration policy.
  • cancellationToken
    A token to cancel both lock acquisition and factory invocation.

Returns

The cached or freshly computed value.

Task<TResult> GetAsync<TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TResult>(TArg1 arg1, TArg2 arg2, TArg3 arg3, TArg4 arg4, TArg5 arg5, TArg6 arg6, TArg7 arg7, TArg8 arg8, Func<TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, Task<TResult>> factory, CachePolicy policy, CancellationToken cancellationToken = default)

Returns a cached result or invokes factory to compute and cache it. The cache key is automatically derived from the caller file path, line number, and the provided arguments.

Type parameters

  • TArg1
    The type of the first argument.
  • TArg2
    The type of the second argument.
  • TArg3
    The type of the third argument.
  • TArg4
    The type of the fourth argument.
  • TArg5
    The type of the fifth argument.
  • TArg6
    The type of the sixth argument.
  • TArg7
    The type of the seventh argument.
  • TArg8
    The type of the eighth argument.
  • TResult
    The type of the cached value.

Parameters

  • arg1
    The first argument passed to the factory and incorporated into the cache key.
  • arg2
    The second argument passed to the factory and incorporated into the cache key.
  • arg3
    The third argument passed to the factory and incorporated into the cache key.
  • arg4
    The fourth argument passed to the factory and incorporated into the cache key.
  • arg5
    The fifth argument passed to the factory and incorporated into the cache key.
  • arg6
    The sixth argument passed to the factory and incorporated into the cache key.
  • arg7
    The seventh argument passed to the factory and incorporated into the cache key.
  • arg8
    The eighth argument passed to the factory and incorporated into the cache key.
  • factory
    The async factory to compute the value on a cache miss.
  • policy
    The cache expiration policy.
  • cancellationToken
    A token to cancel the cache lock acquisition.

Returns

The cached or freshly computed value.

Task<TResult> GetAsync<TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TResult>(TArg1 arg1, TArg2 arg2, TArg3 arg3, TArg4 arg4, TArg5 arg5, TArg6 arg6, TArg7 arg7, TArg8 arg8, Func<TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, CancellationToken, Task<TResult>> factory, CachePolicy policy, CancellationToken cancellationToken = default)

Returns a cached result or invokes factory to compute and cache it. The cache key is automatically derived from the caller file path, line number, and the provided arguments. The CancellationToken is forwarded to the factory for cooperative cancellation.

Type parameters

  • TArg1
    The type of the first argument.
  • TArg2
    The type of the second argument.
  • TArg3
    The type of the third argument.
  • TArg4
    The type of the fourth argument.
  • TArg5
    The type of the fifth argument.
  • TArg6
    The type of the sixth argument.
  • TArg7
    The type of the seventh argument.
  • TArg8
    The type of the eighth argument.
  • TResult
    The type of the cached value.

Parameters

  • arg1
    The first argument passed to the factory and incorporated into the cache key.
  • arg2
    The second argument passed to the factory and incorporated into the cache key.
  • arg3
    The third argument passed to the factory and incorporated into the cache key.
  • arg4
    The fourth argument passed to the factory and incorporated into the cache key.
  • arg5
    The fifth argument passed to the factory and incorporated into the cache key.
  • arg6
    The sixth argument passed to the factory and incorporated into the cache key.
  • arg7
    The seventh argument passed to the factory and incorporated into the cache key.
  • arg8
    The eighth argument passed to the factory and incorporated into the cache key.
  • factory
    The async factory to compute the value on a cache miss. Receives a CancellationToken .
  • policy
    The cache expiration policy.
  • cancellationToken
    A token to cancel both lock acquisition and factory invocation.

Returns

The cached or freshly computed value.

Type

AppSurfaceCachingModule

Source

A AppSurface module that registers the IMemo caching services.