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

Purge cache_key if response headers do not include content digest #22

Merged
merged 2 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/rack/cache/meta_store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ def lookup(request, entity_store)
return nil if match.nil?

_, res = match
if body = entity_store.open(res['x-content-digest'])
entity_key = res['x-content-digest']
if entity_key && body = entity_store.open(entity_key)
restore_response(res, body)
else
# the metastore referenced an entity that doesn't exist in
Expand Down
13 changes: 13 additions & 0 deletions test/meta_store_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,19 @@ def self.call(request); request.path_info.reverse end
mock.verify
end

it 'purges meta store entry when the entry does not contain the digest header' do
cache_key = store_simple_entry
meta_entry = @store.read(cache_key)
meta_entry.grep(Array).flatten.each { |h| h.is_a?(Hash) && h.delete('x-content-digest') }
@store.write(cache_key, meta_entry)
mock = Minitest::Mock.new
mock.expect :call, nil, [@store.cache_key(@request)]
@store.stub(:purge, mock) do
@store.lookup(@request, nil)
end
mock.verify
end

it 'warns once if purge is not implemented' do
store_simple_entry
assert @response.headers['x-content-digest']
Expand Down
Loading