Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Activerecord cache key as timestamp , fixed #5845 #5851

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions activerecord/lib/active_record/integration.rb
Expand Up @@ -33,13 +33,13 @@ def to_param
#
# Product.new.cache_key # => "products/new"
# Product.find(5).cache_key # => "products/5" (updated_at not available)
# Person.find(5).cache_key # => "people/5-20071224150000" (updated_at available)
# Person.find(5).cache_key # => "people/5-1334398193-832774" (updated_at available)
def cache_key
case
when new_record?
"#{self.class.model_name.cache_key}/new"
when timestamp = self[:updated_at]
timestamp = timestamp.utc.to_s(:number)
timestamp = timestamp.utc.to_f.gsub(/\./,'-')
"#{self.class.model_name.cache_key}/#{id}-#{timestamp}"
else
"#{self.class.model_name.cache_key}/#{id}"
Expand Down
2 changes: 1 addition & 1 deletion activerecord/test/cases/base_test.rb
Expand Up @@ -2113,7 +2113,7 @@ def test_cache_key_for_existing_record_is_not_timezone_dependent

def test_cache_key_format_for_existing_record_with_updated_at
dev = Developer.first
assert_equal "developers/#{dev.id}-#{dev.updated_at.utc.to_s(:number)}", dev.cache_key
assert_equal "developers/#{dev.id}-#{dev.updated_at.utc.to_f.gsub(/\./,'-')}", dev.cache_key
end

def test_cache_key_format_for_existing_record_with_nil_updated_at
Expand Down