aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGodfrey Chan <godfreykfc@gmail.com>2014-03-04 17:58:58 -0800
committerGodfrey Chan <godfreykfc@gmail.com>2014-03-04 17:58:58 -0800
commitccf8f27dddcc36fa5c91f614647e0b0bac861d83 (patch)
tree066275df7d4ce82bcc7901bdfb75bfc21cd74b08
parent475c96589ca65282e1a61350271c2f83f0d4044f (diff)
downloadrails-ccf8f27dddcc36fa5c91f614647e0b0bac861d83.tar.gz
rails-ccf8f27dddcc36fa5c91f614647e0b0bac861d83.tar.bz2
rails-ccf8f27dddcc36fa5c91f614647e0b0bac861d83.zip
Revert "Merge pull request #14269 from arthurnn/expanded_key_array"
This reverts commit 475c96589ca65282e1a61350271c2f83f0d4044f, reversing changes made to 705915ab5cf24430892107764b0050c07e1df583. We decided that this is not worth busting everyone's cache as this seems like a very unlikely problem. The problem only occurs when the user is 1) not using a namespace, or 2) using the same namesapce for different *kinds* of cache items. The recommended "fix" is to put those cache items into their own namspace: id = 1 Rails.cache.fetch(id, namespace: "user"){ User.find(id) } ids = [1] Rails.cache.fetch(ids, namespace: "users"){ User.find(ids) } See the discussion on #14269 for details.
-rw-r--r--activesupport/CHANGELOG.md5
-rw-r--r--activesupport/lib/active_support/cache.rb7
-rw-r--r--activesupport/test/caching_test.rb6
3 files changed, 4 insertions, 14 deletions
diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md
index 47580ca0a3..38a761384e 100644
--- a/activesupport/CHANGELOG.md
+++ b/activesupport/CHANGELOG.md
@@ -1,8 +1,3 @@
-* Cache key should add a trailing slash when the key is an array,
- so `cache.fetch('foo')` and `cache.fetch(['foo'])` wont conflict.
-
- *arthurnn*
-
* Change the signature of `fetch_multi` to return a hash rather than an
array. This makes it consistent with the output of `read_multi`.
diff --git a/activesupport/lib/active_support/cache.rb b/activesupport/lib/active_support/cache.rb
index f23f6f16d6..a627fa8651 100644
--- a/activesupport/lib/active_support/cache.rb
+++ b/activesupport/lib/active_support/cache.rb
@@ -511,7 +511,7 @@ module ActiveSupport
# called. If the key is a Hash, then keys will be sorted alphabetically.
def expanded_key(key) # :nodoc:
return key.cache_key.to_s if key.respond_to?(:cache_key)
- trailing_slash = false
+
case key
when Array
if key.size > 1
@@ -519,12 +519,11 @@ module ActiveSupport
else
key = key.first
end
- trailing_slash = true
when Hash
key = key.sort_by { |k,_| k.to_s }.collect{|k,v| "#{k}=#{v}"}
end
- key = key.to_param
- trailing_slash ? "#{key}/" : key
+
+ key.to_param
end
# Prefix a key with the namespace. Namespace and key will be delimited
diff --git a/activesupport/test/caching_test.rb b/activesupport/test/caching_test.rb
index 64d8792dde..18923f61d1 100644
--- a/activesupport/test/caching_test.rb
+++ b/activesupport/test/caching_test.rb
@@ -257,10 +257,6 @@ module CacheStoreBehavior
assert_nil @cache.fetch('foo') { 'baz' }
end
- def test_fetch_with_array_and_without
- assert_not_equal @cache.fetch('foo') { 'barz' }, @cache.fetch(['foo']) { 'barr' }
- end
-
def test_should_read_and_write_hash
assert @cache.write('foo', {:a => "b"})
assert_equal({:a => "b"}, @cache.read('foo'))
@@ -353,7 +349,7 @@ module CacheStoreBehavior
def test_array_as_cache_key
@cache.write([:fu, "foo"], "bar")
- assert_equal "bar", @cache.read("fu/foo/")
+ assert_equal "bar", @cache.read("fu/foo")
end
def test_hash_as_cache_key