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

Properly cache value when it is "false" #2010

Merged
merged 1 commit into from Jul 8, 2011

Conversation

hasclass
Copy link
Contributor

@hasclass hasclass commented Jul 8, 2011

Rails.cache does not properly cache "false", it returns nil instead.

This is because the value is checked with an

if value

...

else
value = nil # => sets false values to nil
end

I changed it to:
if defined?(value)

Example:

Rails.cache.fetch('foo') { false }
=> false # uncached value

Rails.cache.fetch('foo') { false }
=> nil # from cache

@pzac
Copy link

pzac commented Jul 8, 2011

Yeah

@sikachu
Copy link
Member

sikachu commented Jul 8, 2011

Nice catch! 👍

spastorino added a commit that referenced this pull request Jul 8, 2011
Properly cache value when it is "false"
@spastorino spastorino merged commit 4f7ca00 into rails:master Jul 8, 2011
@jamestyj
Copy link

Any chance getting this patch into Rails 3.1?

@vijaydev
Copy link
Member

@jamestyj This will be available in 3.1.2

@jonleighton
Copy link
Member

@vijaydev cherry picking this into 3-1-stable broke the build. the implementation in master has changed since this PR was merged. additionally, the test in this PR actually passes without the fix, so I think even master exhibits this bug still. (also, in the first line of this patch, defined?(value) will always be truthy as it is an argument to the method.)

I am going to revert the cherry-pick for now. I am planning to push 3.1.2rc1 quite soon, but I can wait for a fix for this if you intend to work on it?

@hasclass
Copy link
Contributor Author

@jonleighton This is fixed in master (by using @value = Marshal.dump(value)).

@vijaydev
Copy link
Member

Fixed in cd392fd and passes Travis. Good to go for 3.1.4 :)

@jamestyj
Copy link

Finally, thanks!

rtyley pushed a commit to bfg-repo-cleaner-demos/rails-with-all-non-head-files-deleted that referenced this pull request Sep 11, 2023
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.

None yet

7 participants