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

Change set_cache_headers to before_action #302

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

Conversation

jonsgreen
Copy link
Contributor

Reason for Change

  • While working on a blog post about caching for cfp-app website pages it occurred to be that set_cache_headers should really be called before the controller action to save on server resources and increase the cached response speed when it turns out that the website has not been modified as determined by the call to fresh_when. In that case the 304 Not Modified response should go out as soon as possible.

Changes

  • should be done before rendering to save server resources when
    fresh_when renders head 304
  • adds spec to confirm that pages#show does not get called once cached

- should be done before rendering to save server resources when
  fresh_when renders head 304
- adds spec to confirm that pages#show does not get called once cached
@adarsh adarsh temporarily deployed to cfp-app-flagrant-fix-ca-8uwm1h June 30, 2022 11:46 Inactive
Copy link
Contributor

@adarsh adarsh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great catch! My personal preference is not to call before_ or other callbacks, due to a long history of gotcha-type negative interactions. Rather explicitly call the class/method where used, if possible.

@jonsgreen
Copy link
Contributor Author

@adarsh I tried to move the before_action filters into the actions but I discovered that the behavior of filters is quite special in that if you render or redirect in the filter it cancels the action. The set_cache_headers calls fresh_when which renders head :not_modified when fresh and the whole point is to cancel the action in those cases. I am sure there is some way to work around this but my guess is that you did not foresee that this would not be a trivial change to move the filters into the controller actions. Let me know if you want to discuss.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants