Skip to content

Commit

Permalink
Respect cache timestamp format when giving timestamps to #cache_key
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosantoniodasilva committed Nov 4, 2013
1 parent 91d72fe commit 92c6305
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion activerecord/lib/active_record/integration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ def cache_key(*timestamp_names)
"#{self.class.model_name.cache_key}/new"
when timestamp_names.any?
timestamps = timestamp_names.collect { |method| send(method) }.compact
"#{self.class.model_name.cache_key}/#{id}-#{timestamps.max.utc.to_s(:number)}"
timestamp = timestamps.max.utc.to_s(cache_timestamp_format)
"#{self.class.model_name.cache_key}/#{id}-#{timestamp}"
when timestamp = max_updated_column_timestamp
timestamp = timestamp.utc.to_s(cache_timestamp_format)
"#{self.class.model_name.cache_key}/#{id}-#{timestamp}"
Expand Down
4 changes: 2 additions & 2 deletions activerecord/test/cases/integration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ def test_cache_key_format_is_precise_enough
dev.touch
assert_not_equal key, dev.cache_key
end

def test_named_timestamps_for_cache_key
owner = owners(:blackbeard)
assert_equal "owners/#{owner.id}-#{owner.happy_at.utc.to_s(:number)}", owner.cache_key(:updated_at, :happy_at)
assert_equal "owners/#{owner.id}-#{owner.happy_at.utc.to_s(:nsec)}", owner.cache_key(:updated_at, :happy_at)
end
end

0 comments on commit 92c6305

Please sign in to comment.