Module: CacheHelper
- Defined in:
- app/helpers/cache_helper.rb
Instance Method Summary collapse
- #application_cache_key ⇒ Object
- #cache_digest_for(stringable) ⇒ Object
- #cache_key_for(collection) ⇒ Object
Instance Method Details
#application_cache_key ⇒ Object
20 21 22 |
# File 'app/helpers/cache_helper.rb', line 20 def application_cache_key @_application_cache_key ||= Setting.application_cache_key end |
#cache_digest_for(stringable) ⇒ Object
16 17 18 |
# File 'app/helpers/cache_helper.rb', line 16 def cache_digest_for(stringable) Digest::MD5.hexdigest(stringable.to_s) end |
#cache_key_for(collection) ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 14 |
# File 'app/helpers/cache_helper.rb', line 2 def cache_key_for(collection) count = collection.try(:count) || 1 if collection.is_a? Array return if collection.blank? max_updated_at = collection.reject(&:blank?).max_by(&:updated_at).updated_at.try(:utc).try(:to_s, :number) "#{collection.first.model_name.plural}/all-#{count}-#{max_updated_at}" elsif collection.try :updated_at "#{collection.model_name.plural}/all-#{count}-#{collection.updated_at.try(:utc).try(:to_s, :number)}" else max_updated_at = collection.maximum(:updated_at).try(:utc).try(:to_s, :number) "#{collection.model_name.plural}/all-#{count}-#{max_updated_at}" end end |