workarea-commerce / workarea-api

Adds JSON REST APIs to the Workarea Commerce Platform
https://www.workarea.com
Other
7 stars 1 forks source link

Fix Caching in JBuilder Templates #17

Closed tubbo closed 4 years ago

tubbo commented 4 years ago

To resolve an issue where cached data would still appear in Jbuilder templates even when requesting as a logged-in admin, override the JbuilderTemplate#cache! method to perform the same checks as the ActionView::Helpers::WorkareaCache helper when rendering pages as HTML. This ensures that data between API requests and regular HTML requests on the storefront are consistent. The patch is only active for Storefront API controllers, as Jbuilder is used extensively elsewhere and this kind of cache lookup wouldn't work in those contexts.

bencrouse commented 4 years ago

Let's do this in base, there are jbuilder templates there too, and that's where the cache varies functionality is. It should look something like this: https://github.com/workarea-commerce/workarea/blob/master/core/lib/workarea/ext/freedom_patches/action_view_cache_helper.rb