aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2012-12-10 16:22:30 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2012-12-10 17:48:26 -0300
commit9cce1ea2fd02e8050350c4657e7cc7f1902b8694 (patch)
treee0df45bbb185069b959ed59976475aa580cb4e6c /activerecord/lib/active_record
parent3142bf51ee7afff880b4eb837434dae874b47491 (diff)
downloadrails-9cce1ea2fd02e8050350c4657e7cc7f1902b8694.tar.gz
rails-9cce1ea2fd02e8050350c4657e7cc7f1902b8694.tar.bz2
rails-9cce1ea2fd02e8050350c4657e7cc7f1902b8694.zip
Allow users to choose the timestamp format in the cache key
This can be done using the class attribute cache_timestamp_format Conflicts: railties/guides/source/configuring.textile
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/integration.rb13
1 files changed, 12 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/integration.rb b/activerecord/lib/active_record/integration.rb
index 7bdc1bd4c6..7f877a6471 100644
--- a/activerecord/lib/active_record/integration.rb
+++ b/activerecord/lib/active_record/integration.rb
@@ -1,5 +1,16 @@
module ActiveRecord
module Integration
+ extend ActiveSupport::Concern
+
+ included do
+ ##
+ # :singleton-method:
+ # Indicates the format used to generate the timestamp format in the cache key.
+ # This is +:number+, by default.
+ class_attribute :cache_timestamp_format, :instance_writer => false
+ self.cache_timestamp_format = :nsec
+ end
+
# Returns a String, which Action Pack uses for constructing an URL to this
# object. The default implementation returns this record's id as a String,
# or nil if this record's unsaved.
@@ -37,7 +48,7 @@ module ActiveRecord
when new_record?
"#{self.class.model_name.cache_key}/new"
when timestamp = self[:updated_at]
- timestamp = timestamp.utc.to_s(:nsec)
+ timestamp = timestamp.utc.to_s(cache_timestamp_format)
"#{self.class.model_name.cache_key}/#{id}-#{timestamp}"
else
"#{self.class.model_name.cache_key}/#{id}"