Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow to set custom expires_in #73

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

victorperez
Copy link

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.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant