Skip to content

Commit

Permalink
Merge pull request #153 from randallreedjr/purge-metastore-mismatch
Browse files Browse the repository at this point in the history
Purge key from metastore when entitystore not found
  • Loading branch information
grosser committed Jun 7, 2018
2 parents d12a176 + 669141c commit eb6b995
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
6 changes: 5 additions & 1 deletion CHANGES
@@ -1,6 +1,10 @@
## next

* Meta stores will purge keys when no entity store entries are found

## 1.7.2

* fix key generation for requests with no query strings
* Fix key generation for requests with no query strings

## 1.7.0

Expand Down
6 changes: 3 additions & 3 deletions lib/rack/cache/meta_store.rb
Expand Up @@ -41,9 +41,9 @@ def lookup(request, entity_store)
if body = entity_store.open(res['X-Content-Digest'])
restore_response(res, body)
else
# TODO the metastore referenced an entity that doesn't exist in
# the entitystore. we definitely want to return nil but we should
# also purge the entry from the meta-store when this is detected.
# the metastore referenced an entity that doesn't exist in
# the entitystore, purge the entry from the meta-store
purge(key)
end
end

Expand Down
11 changes: 11 additions & 0 deletions test/meta_store_test.rb
Expand Up @@ -179,6 +179,17 @@ def self.call(request); request.path_info.reverse end
@store.lookup(@request, @entity_store).must_be_nil
end

it 'purges meta store entry when the body does not exist' do
store_simple_entry
@entity_store.purge(@response.headers['X-Content-Digest'])
mock = MiniTest::Mock.new
mock.expect :call, nil, [@store.cache_key(@request)]
@store.stub(:purge, mock) do
@store.lookup(@request, @entity_store)
end
mock.verify
end

it 'restores response headers properly with #lookup' do
store_simple_entry
response = @store.lookup(@request, @entity_store)
Expand Down

0 comments on commit eb6b995

Please sign in to comment.