Permalink
Browse files

Fall back to #to_s for cache key expansion

  • Loading branch information...
jeremy committed Jun 20, 2008
1 parent 72f93b5 commit f47c81ff37afb5e5340b6f2cb47a5bb76b94f5c0
Showing with 9 additions and 1 deletion.
  1. +3 −1 activesupport/lib/active_support/cache.rb
  2. +6 −0 activesupport/test/caching_test.rb
@@ -19,7 +19,7 @@ def self.lookup_store(*store_option)
def self.expand_cache_key(key, namespace = nil)
expanded_cache_key = namespace ? "#{namespace}/" : ""
-
+
if ENV["RAILS_CACHE_ID"] || ENV["RAILS_APP_VERSION"]
expanded_cache_key << "#{ENV["RAILS_CACHE_ID"] || ENV["RAILS_APP_VERSION"]}/"
end
@@ -31,6 +31,8 @@ def self.expand_cache_key(key, namespace = nil)
key.collect { |element| expand_cache_key(element) }.to_param
when key.respond_to?(:to_param)
key.to_param
+ else
+ key.to_s
end
expanded_cache_key
@@ -1,5 +1,11 @@
require 'abstract_unit'
+class CacheKeyTest < Test::Unit::TestCase
+ def test_expand_cache_key
+ assert_equal 'name/1/2/true', ActiveSupport::Cache.expand_cache_key([1, '2', true], :name)
+ end
+end
+
class CacheStoreSettingTest < Test::Unit::TestCase
def test_file_fragment_cache_store
store = ActiveSupport::Cache.lookup_store :file_store, "/path/to/cache/directory"

2 comments on commit f47c81f

@wycats

This comment has been minimized.

Show comment Hide comment
@wycats

wycats Jun 21, 2008

Member

Why is this required? Object#to_param is defined as to_s (http://github.com/rails/rails/tree/master/activesupport/lib/active_support/core_ext/object/conversions.rb)

Member

wycats replied Jun 21, 2008

Why is this required? Object#to_param is defined as to_s (http://github.com/rails/rails/tree/master/activesupport/lib/active_support/core_ext/object/conversions.rb)

@jeremy

This comment has been minimized.

Show comment Hide comment
@jeremy

jeremy Jun 21, 2008

Member

Because it’s overridden in routing_ext to return self for true, false, and nil.

Member

jeremy replied Jun 21, 2008

Because it’s overridden in routing_ext to return self for true, false, and nil.

Please sign in to comment.