Sha256: 4b0571b8ed4b5edd5909c3f2bde49a253ed22cbdd47def6b33d40e255a07c554

Contents?: true

Size: 932 Bytes

Versions: 9

Compression:

Stored size: 932 Bytes

Contents

module HalApi::Controller::Cache
  private

  def index_cache_path
    HalApi::PagedCollection.new(
      filtered(paged(sorted(scoped(resources_base)))),
      request,
      item_class: self.class.resource_class,
      item_decorator: self.class.resource_representer
    ).cache_key
  end

  def show_cache_path
    show_resource.updated_at.utc.to_i
  end

  module ClassMethods
    def cache_api_action(action, options = {})
      options = cache_options.merge(options || {})
      cache_path_method = options.delete(:cache_path_method)
      cache_path_method ||= "#{action}_cache_path"
      unless options[:cache_path]
        options[:cache_path] = lambda do |c|
          c.send(:valid_params_for_action, action).merge _c: send(cache_path_method)
        end
      end
      caches_action(action, options)
    end

    def cache_options
      { compress: true, expires_in: 1.hour, race_condition_ttl: 30 }
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
hal_api-rails-0.2.8 lib/hal_api/controller/cache.rb
hal_api-rails-0.2.7 lib/hal_api/controller/cache.rb
hal_api-rails-0.2.6 lib/hal_api/controller/cache.rb
hal_api-rails-0.2.5 lib/hal_api/controller/cache.rb
hal_api-rails-0.2.4 lib/hal_api/controller/cache.rb
hal_api-rails-0.2.3 lib/hal_api/controller/cache.rb
hal_api-rails-0.2.2 lib/hal_api/controller/cache.rb
hal_api-rails-0.2.1 lib/hal_api/controller/cache.rb
hal_api-rails-0.2.0 lib/hal_api/controller/cache.rb