HybridCache.GetOrCreateAsync Method

Definition

Overloads

GetOrCreateAsync<T>(String, Func<CancellationToken,ValueTask<T>>, HybridCacheEntryOptions, IEnumerable<String>, CancellationToken)

Asynchronously gets the value associated with the key if it exists, or generates a new entry using the provided key and a value from the given factory if the key is not found.

GetOrCreateAsync<TState,T>(String, TState, Func<TState,CancellationToken, ValueTask<T>>, HybridCacheEntryOptions, IEnumerable<String>, CancellationToken)

Asynchronously gets the value associated with the key if it exists, or generates a new entry using the provided key and a value from the given factory if the key is not found.

GetOrCreateAsync<T>(String, Func<CancellationToken,ValueTask<T>>, HybridCacheEntryOptions, IEnumerable<String>, CancellationToken)

Source:
HybridCache.cs

Asynchronously gets the value associated with the key if it exists, or generates a new entry using the provided key and a value from the given factory if the key is not found.

public System.Threading.Tasks.ValueTask<T> GetOrCreateAsync<T> (string key, Func<System.Threading.CancellationToken,System.Threading.Tasks.ValueTask<T>> factory, Microsoft.Extensions.Caching.Hybrid.HybridCacheEntryOptions? options = default, System.Collections.Generic.IEnumerable<string>? tags = default, System.Threading.CancellationToken cancellationToken = default);
member this.GetOrCreateAsync : string * Func<System.Threading.CancellationToken, System.Threading.Tasks.ValueTask<'T>> * Microsoft.Extensions.Caching.Hybrid.HybridCacheEntryOptions * seq<string> * System.Threading.CancellationToken -> System.Threading.Tasks.ValueTask<'T>
Public Function GetOrCreateAsync(Of T) (key As String, factory As Func(Of CancellationToken, ValueTask(Of T)), Optional options As HybridCacheEntryOptions = Nothing, Optional tags As IEnumerable(Of String) = Nothing, Optional cancellationToken As CancellationToken = Nothing) As ValueTask(Of T)

Type Parameters

T

The type of the data being considered.

Parameters

key
String

The key of the entry to look for or create.

factory
Func<CancellationToken,ValueTask<T>>

Provides the underlying data service is the data is not available in the cache.

options
HybridCacheEntryOptions

Additional options for this cache entry.

tags
IEnumerable<String>

The tags to associate with this cache item.

cancellationToken
CancellationToken

The CancellationToken used to propagate notifications that the operation should be canceled.

Returns

The data, either from cache or the underlying data service.

Applies to

GetOrCreateAsync<TState,T>(String, TState, Func<TState,CancellationToken, ValueTask<T>>, HybridCacheEntryOptions, IEnumerable<String>, CancellationToken)

Source:
HybridCache.cs

Asynchronously gets the value associated with the key if it exists, or generates a new entry using the provided key and a value from the given factory if the key is not found.

public abstract System.Threading.Tasks.ValueTask<T> GetOrCreateAsync<TState,T> (string key, TState state, Func<TState,System.Threading.CancellationToken,System.Threading.Tasks.ValueTask<T>> factory, Microsoft.Extensions.Caching.Hybrid.HybridCacheEntryOptions? options = default, System.Collections.Generic.IEnumerable<string>? tags = default, System.Threading.CancellationToken cancellationToken = default);
abstract member GetOrCreateAsync : string * 'State * Func<'State, System.Threading.CancellationToken, System.Threading.Tasks.ValueTask<'T>> * Microsoft.Extensions.Caching.Hybrid.HybridCacheEntryOptions * seq<string> * System.Threading.CancellationToken -> System.Threading.Tasks.ValueTask<'T>
Public MustOverride Function GetOrCreateAsync(Of TState, T) (key As String, state As TState, factory As Func(Of TState, CancellationToken, ValueTask(Of T)), Optional options As HybridCacheEntryOptions = Nothing, Optional tags As IEnumerable(Of String) = Nothing, Optional cancellationToken As CancellationToken = Nothing) As ValueTask(Of T)

Type Parameters

TState

The type of additional state required by factory.

T

The type of the data being considered.

Parameters

key
String

The key of the entry to look for or create.

state
TState

The state required for factory.

factory
Func<TState,CancellationToken,ValueTask<T>>

Provides the underlying data service is the data is not available in the cache.

options
HybridCacheEntryOptions

Additional options for this cache entry.

tags
IEnumerable<String>

The tags to associate with this cache item.

cancellationToken
CancellationToken

The CancellationToken used to propagate notifications that the operation should be canceled.

Returns

The data, either from cache or the underlying data service.

Applies to