Note

Access to this page requires authorization. You can try signing in or .

Access to this page requires authorization. You can try .

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

Definition

Namespace:
Microsoft.Extensions.Caching.Memory
Assembly:
Microsoft.Extensions.Caching.Abstractions.dll
Package:
Microsoft.Extensions.Caching.Abstractions v11.0.0-preview.5.26302.115
Source:
MemoryCacheExtensions.cs
Source:
MemoryCacheExtensions.cs
Source:
MemoryCacheExtensions.cs
Source:
MemoryCacheExtensions.cs

Important

Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.

Tries to get the value associated with the given key.

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

Type Parameters

TItem

The type of the object to get.

Parameters

cache
IMemoryCache

The IMemoryCache instance this method extends.

key
Object

The key of the value to get.

value
TItem

The value associated with the given key.

Returns

true if the key was found; false otherwise.

Remarks

This method returns false both when the key is not present in the cache and when the key is present but the stored value can't be cast to TItem. If you need to distinguish between these two cases (for example, in instrumented caches tracking hit/miss metrics), use the non-generic TryGetValue(Object, Object) method instead, which returns true if the key is present regardless of type.

Applies to


Feedback

Was this page helpful?