Skip to content

Don't use a symbol for the never-cached value #18

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

Merged
merged 2 commits into from
Mar 14, 2025

Conversation

kuszmaul
Copy link
Contributor

@kuszmaul kuszmaul commented Mar 13, 2025

Use an internal singleton value, so that if the user has some reason to make a MultiThreadedCache{K, Symbol} they won't get strange behavior if they happen to store :__MultiThreadedCaches_key_not_found__.

In particular this could happen in the original code:

julia> c=MultiThreadedCache{Int, Symbol}()
MultiThreadedCache{Int64, Symbol}(Dict{Int64, Symbol}())

julia> MultiThreadedCaches.init_cache!(c)
MultiThreadedCache{Int64, Symbol}(Dict{Int64, Symbol}())

julia> get!(c, 4) do; :__MultiThreadedCaches_key_not_found__ end
:__MultiThreadedCaches_key_not_found__

julia> get!(c, 4) do; :hello end
:hello

where we didn't expect to get :hello on the second get!.

@kuszmaul kuszmaul changed the title Don't use a symbol for the never-cached value, use a an internal sing… Don't use a symbol for the never-cached value Mar 13, 2025
@nickrobinson251 nickrobinson251 merged commit 02e279f into JuliaConcurrent:main Mar 14, 2025
12 of 18 checks passed
@nickrobinson251
Copy link
Collaborator

Thanks, @kuszmaul !

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.

2 participants