Skip to content

Commit

Permalink
fix(HTTP Cache): Use cache_key_with_version for etag
Browse files Browse the repository at this point in the history
The cache_key is just the page id. We need to include
the cache_version (the page published_at date).
  • Loading branch information
tvdeyen committed May 6, 2024
1 parent 94c4a10 commit ecfcd22
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/controllers/alchemy/json_api/pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def index
@pages = filtered_pages.result
if !@pages.all?(&:cache_page?)
render_pages_json(allowed) && return
elsif stale?(last_modified: @pages.maximum(:published_at), etag: @pages.max_by(&:cache_key)&.cache_key)
elsif stale?(last_modified: @pages.maximum(:published_at), etag: @pages.max_by(&:cache_key_with_version)&.cache_key_with_version)
render_pages_json(allowed)
end
end
Expand All @@ -25,7 +25,7 @@ def show
render(jsonapi: api_page(load_page)) && return
end

if stale?(last_modified: last_modified_for(@page), etag: @page.cache_key)
if stale?(last_modified: last_modified_for(@page), etag: @page.cache_key_with_version)
# Only load page with all includes when browser cache is stale
render jsonapi: api_page(load_page)
end
Expand Down

0 comments on commit ecfcd22

Please sign in to comment.