Skip to content

Conversation

@mgravell
Copy link
Contributor

Implement MemoryCache.TryGetValue APIs taking ReadOnlySpan<char>, as approved in #110504

fix #110504

@Copilot Copilot AI review requested due to automatic review settings February 19, 2025 15:32
@ghost
Copy link

ghost commented Feb 19, 2025

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.

1 similar comment
@ghost
Copy link

ghost commented Feb 19, 2025

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

- demand GetAlternateLookup works on the target runtimes
- rely on documented "out set to default on failure" lookup behavior
@mgravell
Copy link
Contributor Author

@stephentoub made less defensive in 4f60149, per feedback

public bool TryGetValue(System.ReadOnlySpan<char> key, out object? value) { throw null; }
[System.Runtime.CompilerServices.OverloadResolutionPriority(1)]
public bool TryGetValue<TItem>(System.ReadOnlySpan<char> key, out TItem? value) { throw null; }
#endif
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


CoherentState coherentState = _coherentState; // Clear() can update the reference in the meantime
if (coherentState.TryGetValue(key, out CacheEntry? tmp))
coherentState.TryGetValue(key, out CacheEntry? entry); // note we rely on documented "default when fails" contract re the out
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could formalize the comment with an assert, e.g.

Suggested change
coherentState.TryGetValue(key, out CacheEntry? entry); // note we rely on documented "default when fails" contract re the out
bool success = coherentState.TryGetValue(key, out CacheEntry? entry);
Debug.Assert(success || entry is null, "We rely on documented 'default when fails' contract.");

/// <param name="value">The located value or null.</param>
/// <returns>True if the key was found.</returns>
/// <remarks>This method allows values with <see cref="string"/> keys to be queried by content without allocating a new <see cref="string"/> instance.</remarks>
[OverloadResolutionPriority(1)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@333fred, @jaredpar, just FYI on more use of ORPA.

@mgravell mgravell merged commit 7e9343b into dotnet:main Feb 20, 2025
3 checks passed
@stephentoub
Copy link
Member

This didn't actually run CI

@stephentoub
Copy link
Member

It also merged with https://github.com/dotnet/runtime/pull/112695/files#r1963779247 unaddressed

@mgravell
Copy link
Contributor Author

mgravell commented Feb 20, 2025 via email

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[API Proposal]: M.E.C.M. MemoryCache - add ReadOnlySpan<char> get API

3 participants