Sha256: e5ecdc20ea8d219ee21fa17579ee8c6d25d8775fe518ef4a4b947d7d6f508805

Contents?: true

Size: 855 Bytes

Versions: 1

Compression:

Stored size: 855 Bytes

Contents

module CacheHelper
  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

  def cache_digest_for(stringable)
    Digest::MD5.hexdigest(stringable.to_s)
  end

  def application_cache_key
    @_application_cache_key ||= Setting.application_cache_key
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
forest_cms-0.98.1 app/helpers/cache_helper.rb