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

Ignore cache for nil on non-nil types? #3

Open
jwoertink opened this issue Nov 21, 2021 · 0 comments
Open

Ignore cache for nil on non-nil types? #3

jwoertink opened this issue Nov 21, 2021 · 0 comments

Comments

@jwoertink
Copy link
Member

Say you have some logic that may return nil, but you don't want to cache nil... Is this something where we could do this?

cache.fetch(key, as: String) do
  [nil, "string"].sample
end

With this, I specify that the value is String, but if it returns nil, then we don't cache it. Running it again would only cache if the value returns "string". However, doing this...

cache.fetch(key, as: String?) do
  [nil, "string"].sample
end

would say that I allow a nil value, so cache whatever I get back, even if it's nil.

I think we can catch that at compile-time and alter the logic. But the question is, would that be nice? Or would that cause issues?

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

No branches or pull requests

1 participant