actionpack-action_caching icon indicating copy to clipboard operation
actionpack-action_caching copied to clipboard

allow to set custom expires_in

Open victorperez opened this issue 5 years ago • 0 comments

On apps with controllers that only use the default CRUD actions it is quite common to extract the action caching logic to a concern to be able to the share the same logic between controllers and to reason about the caching strategy in a single place, the concern could be similar to this one:

module SetActionCaching
  extend ActiveSupport::Concern

  included do
    caches_action :index, :show,
      cache_path: :cache_path, expires_in: 2.hours, if: :cacheable_action?
  end

  ...
end

The issue with this approach is that action caching does not allow to set a custom expires_in which force all controllers to use the same expire time, this PR allow to set a custom expires_in time using a symbol as caches_action :index, expires_in: :set_expires_in or even a custom object which will allow to extract all the logic into the concern. This can be also useful if different expire times for a single action are needed.

victorperez avatar Jun 11 '20 04:06 victorperez