@@ -25,69 +25,75 @@ module Strategy
25
25
autoload :LocalCache , 'active_support/cache/strategy/local_cache'
26
26
end
27
27
28
- # Creates a new CacheStore object according to the given options.
29
- #
30
- # If no arguments are passed to this method, then a new
31
- # ActiveSupport::Cache::MemoryStore object will be returned.
32
- #
33
- # If you pass a Symbol as the first argument, then a corresponding cache
34
- # store class under the ActiveSupport::Cache namespace will be created.
35
- # For example:
36
- #
37
- # ActiveSupport::Cache.lookup_store(:memory_store)
38
- # # => returns a new ActiveSupport::Cache::MemoryStore object
39
- #
40
- # ActiveSupport::Cache.lookup_store(:mem_cache_store)
41
- # # => returns a new ActiveSupport::Cache::MemCacheStore object
42
- #
43
- # Any additional arguments will be passed to the corresponding cache store
44
- # class's constructor:
45
- #
46
- # ActiveSupport::Cache.lookup_store(:file_store, "/tmp/cache")
47
- # # => same as: ActiveSupport::Cache::FileStore.new("/tmp/cache")
48
- #
49
- # If the first argument is not a Symbol, then it will simply be returned:
50
- #
51
- # ActiveSupport::Cache.lookup_store(MyOwnCacheStore.new)
52
- # # => returns MyOwnCacheStore.new
53
- def self . lookup_store ( *store_option )
54
- store , *parameters = *Array . wrap ( store_option ) . flatten
55
-
56
- case store
57
- when Symbol
58
- store_class_name = store . to_s . camelize
59
- store_class =
60
- begin
61
- require "active_support/cache/#{ store } "
62
- rescue LoadError => e
63
- raise "Could not find cache store adapter for #{ store } (#{ e } )"
64
- else
65
- ActiveSupport ::Cache . const_get ( store_class_name )
66
- end
67
- store_class . new ( *parameters )
68
- when nil
69
- ActiveSupport ::Cache ::MemoryStore . new
70
- else
71
- store
28
+ class << self
29
+ # Creates a new CacheStore object according to the given options.
30
+ #
31
+ # If no arguments are passed to this method, then a new
32
+ # ActiveSupport::Cache::MemoryStore object will be returned.
33
+ #
34
+ # If you pass a Symbol as the first argument, then a corresponding cache
35
+ # store class under the ActiveSupport::Cache namespace will be created.
36
+ # For example:
37
+ #
38
+ # ActiveSupport::Cache.lookup_store(:memory_store)
39
+ # # => returns a new ActiveSupport::Cache::MemoryStore object
40
+ #
41
+ # ActiveSupport::Cache.lookup_store(:mem_cache_store)
42
+ # # => returns a new ActiveSupport::Cache::MemCacheStore object
43
+ #
44
+ # Any additional arguments will be passed to the corresponding cache store
45
+ # class's constructor:
46
+ #
47
+ # ActiveSupport::Cache.lookup_store(:file_store, "/tmp/cache")
48
+ # # => same as: ActiveSupport::Cache::FileStore.new("/tmp/cache")
49
+ #
50
+ # If the first argument is not a Symbol, then it will simply be returned:
51
+ #
52
+ # ActiveSupport::Cache.lookup_store(MyOwnCacheStore.new)
53
+ # # => returns MyOwnCacheStore.new
54
+ def lookup_store ( *store_option )
55
+ store , *parameters = *Array . wrap ( store_option ) . flatten
56
+
57
+ case store
58
+ when Symbol
59
+ store_class_name = store . to_s . camelize
60
+ store_class =
61
+ begin
62
+ require "active_support/cache/#{ store } "
63
+ rescue LoadError => e
64
+ raise "Could not find cache store adapter for #{ store } (#{ e } )"
65
+ else
66
+ ActiveSupport ::Cache . const_get ( store_class_name )
67
+ end
68
+ store_class . new ( *parameters )
69
+ when nil
70
+ ActiveSupport ::Cache ::MemoryStore . new
71
+ else
72
+ store
73
+ end
72
74
end
73
- end
74
75
75
- def self . expand_cache_key ( key , namespace = nil )
76
- expanded_cache_key = namespace ? "#{ namespace } /" : ""
76
+ def expand_cache_key ( key , namespace = nil )
77
+ expanded_cache_key = namespace ? "#{ namespace } /" : ""
78
+
79
+ prefix = ENV [ "RAILS_CACHE_ID" ] || ENV [ "RAILS_APP_VERSION" ]
80
+ if prefix
81
+ expanded_cache_key << "#{ prefix } /"
82
+ end
77
83
78
- prefix = ENV [ "RAILS_CACHE_ID" ] || ENV [ "RAILS_APP_VERSION" ]
79
- if prefix
80
- expanded_cache_key << "#{ prefix } /"
84
+ expanded_cache_key << retrieve_cache_key ( key )
85
+ expanded_cache_key
81
86
end
82
87
83
- expanded_cache_key <<
88
+ private
89
+
90
+ def retrieve_cache_key ( key )
84
91
case
85
92
when key . respond_to? ( :cache_key ) then key . cache_key
86
- when key . is_a? ( Array ) then key . map { |element | expand_cache_key ( element ) } . to_param
93
+ when key . is_a? ( Array ) then key . map { |element | retrieve_cache_key ( element ) } . to_param
87
94
else key . to_param
88
95
end . to_s
89
-
90
- expanded_cache_key
96
+ end
91
97
end
92
98
93
99
# An abstract cache store class. There are multiple cache store
0 commit comments