Sha256: ef9399cd8e1b18053a43203df872ede61497a50b3d7676a853d38b5260ceda18

Contents?: true

Size: 1.1 KB

Versions: 14

Compression:

Stored size: 1.1 KB

Contents

module HoboCacheHelper
  def hobo_cache_key(namespace=:views, route_on=nil, query_params=nil, attributes=nil)
    attributes ||= {}

    if route_on == true
      route_on = this
    end

    if route_on.is_a?(ActiveRecord::Base)
      route_on = url_for(route_on)
    end

    if route_on
      attributes.reverse_merge!(Rails.application.routes.recognize_path(route_on))
    elsif params[:page_path]
      # it's quite possible that our page was rendered by a different action, so normalize
      attributes.reverse_merge!(Rails.application.routes.recognize_path(params[:page_path]))
    end

    key_attrs = attributes
    key_attrs[:only_path] = false
    comma_split(query_params || "").each do |qp|
      key_attrs["#{qp}"] = params[qp] || ""
    end

    key = ActiveSupport::Cache.expand_cache_key(url_for(key_attrs).split('://').last, namespace)
    Digest::MD5.hexdigest(key)
  end

  def item_cache(*args, &block)
    unless Rails.configuration.action_controller.perform_caching
      yield if block_given?
    else
      key = hobo_cache_key(:item, *args)
      Rails.cache.fetch(key, &block)
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
hobo_rapid-2.2.6 app/helpers/hobo_cache_helper.rb
hobo_rapid-2.2.5 app/helpers/hobo_cache_helper.rb
hobo_rapid-2.2.4 app/helpers/hobo_cache_helper.rb
hobo_rapid-2.2.3 app/helpers/hobo_cache_helper.rb
hobo_rapid-2.2.2 app/helpers/hobo_cache_helper.rb
hobo_rapid-2.2.1 app/helpers/hobo_cache_helper.rb
hobo_rapid-2.2.0 app/helpers/hobo_cache_helper.rb
hobo_rapid-2.1.2 app/helpers/hobo_cache_helper.rb
hobo_rapid-2.1.1 app/helpers/hobo_cache_helper.rb
hobo_rapid-2.1.0 app/helpers/hobo_cache_helper.rb
hobo_rapid-2.1.0.pre4 app/helpers/hobo_cache_helper.rb
hobo_rapid-2.1.0.pre3 app/helpers/hobo_cache_helper.rb
hobo_rapid-2.1.0.pre2 app/helpers/hobo_cache_helper.rb
hobo_rapid-2.1.0.pre1 app/helpers/hobo_cache_helper.rb