lib/fish0/concerns/cacheable.rb in fish0-0.1.2 vs lib/fish0/concerns/cacheable.rb in fish0-0.2.0
- old
+ new
@@ -4,14 +4,13 @@
extend ActiveSupport::Concern
included do
def cache_key(*timestamp_names)
if timestamp_names.any?
- timestamp = max_updated_column_timestamp(timestamp_names)
- "#{self.class.to_s.tableize}/#{primary_key_value}-#{timestamp.utc.to_s(:nsec)}"
- elsif timestamp = max_updated_column_timestamp
- "#{self.class.to_s.tableize}/#{primary_key_value}-#{timestamp.utc.to_s(:nsec)}"
+ cache_key_string(max_updated_column_timestamp(timestamp_names))
+ elsif (timestamp = max_updated_column_timestamp)
+ cache_key_string(timestamp)
else
"#{self.class.to_s.tableize}/#{primary_key_value}"
end
end
@@ -25,9 +24,13 @@
timestamp_names
.map { |attr| self[attr] }
.compact
.map(&:to_time)
.max
+ end
+
+ def cache_key_string(timestamp)
+ "#{self.class.to_s.tableize}/#{primary_key_value}-#{timestamp.utc.to_s(:nsec)}"
end
end
end
end
end