Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

technicianted
Copy link

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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant