CacheExtensions.TryGetValue<TItem>(IMemoryCache, Object, TItem) Metodo

Definizione

Prova a ottenere il valore associato alla chiave specificata.

public:
generic <typename TItem>
[System::Runtime::CompilerServices::Extension]
 static bool TryGetValue(Microsoft::Extensions::Caching::Memory::IMemoryCache ^ cache, System::Object ^ key, [Runtime::InteropServices::Out] TItem % value);
public static bool TryGetValue<TItem>(this Microsoft.Extensions.Caching.Memory.IMemoryCache cache, object key, out TItem? value);
static member TryGetValue : Microsoft.Extensions.Caching.Memory.IMemoryCache * obj * 'Item -> bool
<Extension()>
Public Function TryGetValue(Of TItem) (cache As IMemoryCache, key As Object, ByRef value As TItem) As Boolean

Parametri di tipo

TItem

Tipo dell'oggetto da ottenere.

Parametri

cache
IMemoryCache

L'istanza IMemoryCache di questo metodo si estende.

key
Object

Chiave del valore da ottenere.

value
TItem

Valore associato alla chiave specificata.

Valori restituiti

true se la chiave è stata trovata; false Altrimenti.

Commenti

Questo metodo restituisce false entrambi quando la chiave non è presente nella cache e quando la chiave è presente, ma non è possibile eseguire il cast del valore archiviato in TItem. Se è necessario distinguere tra questi due casi (ad esempio, nelle metriche di rilevamento riscontri/mancati riscontri nella cache instrumentata), usare invece il metodo non generico TryGetValue(Object, Object) , che restituisce true se la chiave è presente indipendentemente dal tipo.

Si applica a