This project is archived and is in readonly mode.
Rails.cache.fetch does not work with false boolean as cached value
-
Thijs de Vries
That last patch I sent caused some of the tests to fail. This one won't fail any tests and allows for the new ones to pass.
-
DHH
Won't this lead to a race condition? You have two calls to the separate cache to check for the same key. The key could have come and gone in between those two calls.
-
Derek McLoughlin
Would it be better to have the following:
if !options[:force] && ((value = read(key, options)) != nil) -
Thijs de Vries
- Tag cleared.
@@@ruby if !options[:force] && ((value = read(key, options)) != nil)
won't let you store nil as a value. In case a really expensive function returns nil, one may still wanna store nil so they don't have to run the really expensive function again. Probably have to work with thread locks to make this work. -
Derek McLoughlin
True, but nil is currently being used as meaning "the thing isn't in the cache". The above solution works for cached values of 'false'.
-
MatthewRudy
- Assigned user set to José Valim
- Tag set to activesupport, cache, false, fetch
hey,
what happened to this?The "false" case of this bit me and a colleague again this week.
Spent ages wondering why using memcache was even slower than hitting our DB.So here is a patch, just to deal with the "false" case.
But I feel that there should be a more clever way to deal with a nil store.
Anyway,
here is my patch.http://github.com/matthewrudy/rude-rails/commit/37d50e8e4d4eec27e06...
-
José Valim
- Assigned user cleared.
-
MatthewRudy
living the dream!
-
MatthewRudy
my patch still works
http://github.com/matthewrudy/rude-rails/commit/6cb522c735d8fa9895b...and I upped the patch
but now its a bit weird
(I think because of the rebase) -
W. Andrew Loe III
Chris Kampmeier in #3482 Activesupport caching can't fetch cached boolean false, always re-calculates appears to have come up with a patch that does not introduce a race condition.
-
Santiago Pastorino
- State changed from new to open
- Importance changed from to
This issue has been automatically marked as stale because it has not been commented on for at least three months.
The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.
Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.
-
Santiago Pastorino
- State changed from open to stale
