Skip to content

GetOrSet method to handle case for atomic get and set if not exists - #117

Open
technicianted wants to merge 1 commit into
patrickmn:masterfrom
technicianted:technicianted/getorset
Open

technicianted wants to merge 1 commit into
patrickmn:masterfrom
technicianted:technicianted/getorset

Conversation

@technicianted

Copy link
Copy Markdown

This PR adds a new method GetOrSet to handle the case where we run into a race when multiple threads do "if not found then set" sequence. Without using GetOrSet, callers will have to use global locks, then perform 1-2 cache operations (Add followed by Get if already exists) which would be redundant and inefficient.

There was a similar PR #82 but it tried to do it using a closure instead of a simple value. This PR takes a much simpler approach to avoid potential long held locks by external code.

Repository owner deleted a comment from pablodz Jan 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant