Skip to content

Commit 5041469

Browse files
Copilotjozkee
andcommitted
Update CacheExtensions documentation to clarify type-check behavior
Co-authored-by: jozkee <[email protected]>
1 parent fc564a6 commit 5041469

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

xml/Microsoft.Extensions.Caching.Memory/CacheExtensions.xml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,9 @@
113113
<param name="cache">The <see cref="T:Microsoft.Extensions.Caching.Memory.IMemoryCache" /> instance this method extends.</param>
114114
<param name="key">The key of the value to get.</param>
115115
<summary>
116-
Gets the value associated with this key if present.
116+
Gets the value associated with this key if present and castable to <typeparamref name="TItem" />.
117117
</summary>
118-
<returns>The value associated with this key, or <c>default(TItem)</c> if the key is not present.</returns>
118+
<returns>The value associated with this key, or <c>default(TItem)</c> if the key is not present or the stored value can't be cast to <typeparamref name="TItem" />.</returns>
119119
<remarks>To be added.</remarks>
120120
</Docs>
121121
</Member>
@@ -595,13 +595,15 @@
595595
<typeparam name="TItem">The type of the object to get.</typeparam>
596596
<param name="cache">The <see cref="T:Microsoft.Extensions.Caching.Memory.IMemoryCache" /> instance this method extends.</param>
597597
<param name="key">The key of the value to get.</param>
598-
<param name="value">The value associated with the given key.</param>
598+
<param name="value">The value associated with the given key, or <c>default(TItem)</c> if the key is not found or the stored value can't be cast to <typeparamref name="TItem" />.</param>
599599
<summary>
600-
Tries to get the value associated with the given key.
600+
Tries to get the value associated with the given key and cast it to <typeparamref name="TItem" />.
601601
</summary>
602602
<returns>
603-
<c>true</c> if the key was found; <c>false</c> otherwise.</returns>
604-
<remarks>To be added.</remarks>
603+
<c>true</c> if the key was found and the stored value can be cast to <typeparamref name="TItem" />; <c>false</c> otherwise.</returns>
604+
<remarks>
605+
This method returns <c>false</c> 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 <typeparamref name="TItem" />. If you need to distinguish between these two cases (for example, in instrumented caches tracking hit/miss metrics), use the non-generic <see cref="M:Microsoft.Extensions.Caching.Memory.IMemoryCache.TryGetValue(System.Object,System.Object@)" /> method instead, which returns <c>true</c> if the key is present regardless of type.
606+
</remarks>
605607
</Docs>
606608
</Member>
607609
</Members>

0 commit comments

Comments
 (0)