diff --git a/lib/rack/cache/meta_store.rb b/lib/rack/cache/meta_store.rb index 7fc63a9..ec37f35 100644 --- a/lib/rack/cache/meta_store.rb +++ b/lib/rack/cache/meta_store.rb @@ -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 diff --git a/test/meta_store_test.rb b/test/meta_store_test.rb index 69284c8..5071a81 100644 --- a/test/meta_store_test.rb +++ b/test/meta_store_test.rb @@ -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']