Changeset 8415
- Timestamp:
- 12/16/07 16:56:42 (9 months ago)
- Files:
-
- branches/2-1-caching/actionpack/lib/action_controller/caching.rb (modified) (2 diffs)
- branches/2-1-caching/actionpack/lib/action_controller/caching/fragments.rb (modified) (3 diffs)
- branches/2-1-caching/activerecord/lib/active_record/base.rb (modified) (1 diff)
- branches/2-1-caching/activesupport/lib/active_support/cache.rb (modified) (1 diff)
- branches/2-1-caching/activesupport/lib/active_support/core_ext/date/conversions.rb (modified) (1 diff)
- branches/2-1-caching/activesupport/lib/active_support/core_ext/time/conversions.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/2-1-caching/actionpack/lib/action_controller/caching.rb
r8414 r8415 57 57 def cache(key, options = nil, &block) 58 58 if cache_configured? 59 cache_store.fetch( key.to_param, options, &block)59 cache_store.fetch(ActiveSupport::Cache.expand_cache_key(key, :controller), options, &block) 60 60 else 61 61 yield … … 64 64 65 65 66 private 66 private 67 67 def cache_configured? 68 68 self.class.cache_configured? branches/2-1-caching/actionpack/lib/action_controller/caching/fragments.rb
r8414 r8415 58 58 # value of url_for on that hash (without the protocol). 59 59 def fragment_cache_key(key) 60 key.is_a?(Hash) ? url_for(key).split("://").last : key.to_param60 ActiveSupport::Cache.expand_cache_key(key.is_a?(Hash) ? url_for(key).split("://").last : key, :fragments) 61 61 end 62 62 … … 82 82 key = fragment_cache_key(key) 83 83 84 self.class.benchmark "Cached fragment : #{key}" do84 self.class.benchmark "Cached fragment miss: #{key}" do 85 85 cache_store.write(key, content, options) 86 86 end … … 95 95 key = fragment_cache_key(key) 96 96 97 self.class.benchmark " Fragment read: #{key}" do97 self.class.benchmark "Cached fragment hit: #{key}" do 98 98 cache_store.read(key, options) 99 99 end branches/2-1-caching/activerecord/lib/active_record/base.rb
r8381 r8415 1948 1948 (id = self.id) ? id.to_s : nil # Be sure to stringify the id for routes 1949 1949 end 1950 1951 # Returns a cache key that can be used to identify this record. Examples: 1952 # 1953 # Product.new.cache_key # => "products/new" 1954 # Product.find(5).cache_key # => "products/5" (updated_at not available) 1955 # Person.find(5).cache_key # => "people/5-20071224150000" (updated_at available) 1956 def cache_key 1957 case 1958 when new_record? 1959 "#{self.class.name.tableize}/new" 1960 when self[:updated_at] 1961 "#{self.class.name.tableize}/#{id}-#{updated_at.to_s(:number)}" 1962 else 1963 "#{self.class.name.tableize}/#{id}" 1964 end 1965 end 1950 1966 1951 1967 def id_before_type_cast #:nodoc: branches/2-1-caching/activesupport/lib/active_support/cache.rb
r8394 r8415 14 14 store 15 15 end 16 end 17 18 def self.expand_cache_key(key, namespace = nil) 19 expanded_cache_key = namespace ? "#{namespace}/" : "" 20 21 if ENV["RAILS_CACHE_ID"] || ENV["RAILS_APP_VERSION"] 22 expanded_cache_key << "#{ENV["RAILS_CACHE_ID"] || ENV["RAILS_APP_VERSION"]}/" 23 end 24 25 expanded_cache_key << case 26 when key.respond_to?(:cache_key) 27 key.cache_key 28 when key.is_a?(Array) 29 key.collect { |element| expand_cache_key(element) }.to_param 30 when key.respond_to?(:to_param) 31 key.to_param 32 end 33 34 expanded_cache_key 16 35 end 17 36 branches/2-1-caching/activesupport/lib/active_support/core_ext/date/conversions.rb
r8279 r8415 8 8 :long => "%B %e, %Y", 9 9 :db => "%Y-%m-%d", 10 :number => "%Y%m%d", 10 11 :long_ordinal => lambda { |date| date.strftime("%B #{date.day.ordinalize}, %Y") }, # => "April 25th, 2007" 11 12 :rfc822 => "%e %b %Y" branches/2-1-caching/activesupport/lib/active_support/core_ext/time/conversions.rb
r8278 r8415 6 6 DATE_FORMATS = { 7 7 :db => "%Y-%m-%d %H:%M:%S", 8 :number => "%Y%m%d%H%M%S", 8 9 :time => "%H:%M", 9 10 :short => "%d %b %H:%M",