Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Cache#_fetch correctly handles cached 'false' #145

Open
wants to merge 1 commit into from

1 participant

Mike Ragalie
Mike Ragalie

ActiveSupport::Cache now caches 'false': rails/rails@cd392fd

This PR causes Cache#_fetch to return a cached 'false' without performing another lookup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 1, 2012
  1. Mike Ragalie
This page is out of date. Refresh to see the latest.
Showing with 8 additions and 1 deletion.
  1. +2 −1  lib/i18n/backend/cache.rb
  2. +6 −0 test/backend/cache_test.rb
3  lib/i18n/backend/cache.rb
View
@@ -76,7 +76,8 @@ def fetch(cache_key, &block)
end
def _fetch(cache_key, &block)
- result = I18n.cache_store.read(cache_key) and return result
+ result = I18n.cache_store.read(cache_key)
+ return result unless result.nil?
result = catch(:exception, &block)
I18n.cache_store.write(cache_key, result) unless result.is_a?(Proc)
result
6 test/backend/cache_test.rb
View
@@ -36,6 +36,12 @@ def teardown
assert_equal 'Bar', I18n.t(:bar)
end
+ test "translate returns a cached false response" do
+ I18n.backend.expects(:lookup).never
+ I18n.cache_store.expects(:read).returns(false)
+ assert_equal false, I18n.t(:foo)
+ end
+
test "still raises MissingTranslationData but also caches it" do
assert_raise(I18n::MissingTranslationData) { I18n.t(:missing, :raise => true) }
assert_raise(I18n::MissingTranslationData) { I18n.t(:missing, :raise => true) }
Something went wrong with that request. Please try again.