mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Include cache key in ModelName
This commit is contained in:
parent
6874caa407
commit
071fe79279
2 changed files with 7 additions and 6 deletions
|
@ -2170,11 +2170,11 @@ module ActiveRecord #:nodoc:
|
||||||
def cache_key
|
def cache_key
|
||||||
case
|
case
|
||||||
when new_record?
|
when new_record?
|
||||||
"#{self.class.name.tableize}/new"
|
"#{self.class.model_name.cache_key}/new"
|
||||||
when self[:updated_at]
|
when timestamp = self[:updated_at]
|
||||||
"#{self.class.name.tableize}/#{id}-#{updated_at.to_s(:number)}"
|
"#{self.class.model_name.cache_key}/#{id}-#{timestamp.to_s(:number)}"
|
||||||
else
|
else
|
||||||
"#{self.class.name.tableize}/#{id}"
|
"#{self.class.model_name.cache_key}/#{id}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
module ActiveSupport
|
module ActiveSupport
|
||||||
class ModelName < String
|
class ModelName < String
|
||||||
attr_reader :singular, :plural, :partial_path
|
attr_reader :singular, :plural, :cache_key, :partial_path
|
||||||
|
|
||||||
def initialize(name)
|
def initialize(name)
|
||||||
super
|
super
|
||||||
@singular = underscore.tr('/', '_').freeze
|
@singular = underscore.tr('/', '_').freeze
|
||||||
@plural = @singular.pluralize.freeze
|
@plural = @singular.pluralize.freeze
|
||||||
@partial_path = "#{tableize}/#{demodulize.underscore}".freeze
|
@cache_key = tableize
|
||||||
|
@partial_path = "#{@cache_key}/#{demodulize.underscore}".freeze
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue