-
Notifications
You must be signed in to change notification settings - Fork 450
Fix fragment_cache_key cache invalidation #341
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
Conversation
|
Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @rwz (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
3d74e41 to
f39e8b8
Compare
|
👍. It's a bit of a smell that each of the template engines have to implement this logic themselves. Wonder what we can do at a higher level to prevent that. |
|
Ideally, Jbuilder and others could use the Rails caching helpers more directly, but they don't work with non-string objects. See action_view/helpers/cache_helper.rb#L227-L238 and abstract_controller/caching/fragments.rb#L77. |
|
I think it's worth considering folding Jbuilder into Rails so it can move forward at the same pace. In its current form, it has to remain backwards compatible with a number of Rails versions, and has accumulated gunk like jbuilder/jbuilder_template.rb#L137-L146. |
|
Yeah, possibly. Currently the default serialization format for Rails API is On Tue, Jun 14, 2016 at 3:28 PM, Javan Makhmali [email protected]
|
|
I prefer to create better abstractions in rails han fold all gems to the
|
|
I'll second the notion of finding a better public opt-in API for templates. It's clear that what we do in rails/rails#25825 won't automatically arrive in Jbuilder either, and that's a shame. From the caching side of things templates just need to be able to read and write fragments (or maybe a fetch fragment method could do). That module should then handle: does the controller enable caching, is there a cache store setup, making sure instrumentation is done correctly, etc. That's the high points as I see it at least. |
For that to happen, the Rails caching helpers will need to work with non-string objects. Jbuilder's "fragments" are objects like Hashes and Arrays. See #341 (comment) |
|
Ah, right on. Yeah, it's pretty much a non-starter without that support. Hm, |
|
This change removed the ability to use the :force option with cache! now that it uses Rails.cache.read and Rails.cache.write instead of Rails.cache.fetch. |
Jbuilder currently does not account for an app's controller-wide
fragment_cache_keys when computing its cache keys.This change adds support, and also aligns Jbuilder's caching setup with ActionView's cache helpers and Abstract Controller's fragment caching and instrumentation.
To test, I made a fresh app with a
fragment_cache_keycall that should invalidate the template's cache with every request.Requests using Jbuilder 2.5.0
$ curl http://0.0.0.0:3000/widgets.json {"config_x_counter":1} $ curl http://0.0.0.0:3000/widgets.json {"config_x_counter":1}Requests using this branch
$ curl http://0.0.0.0:3000/widgets.json {"config_x_counter":1} $ curl http://0.0.0.0:3000/widgets.json {"config_x_counter":2}Note that the cache was correctly invalidated and the presence logging like you'd see when using
cachein an .erb template./cc @jeremy