Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #66 from newsline/degrade-gracefully

Gracefully degrade when cache store goes offline
  • Loading branch information...
commit b4f8ce90be6335706a85058d24acce1f5c6364a9 2 parents 06d089a + fcb3fbb
Ryan Tomayko authored
Showing with 21 additions and 1 deletion.
  1. +1 −1  lib/rack/cache/metastore.rb
  2. +20 −0 test/metastore_test.rb
2  lib/rack/cache/metastore.rb
View
@@ -64,7 +64,7 @@ def store(request, response, entity_store)
end
response.headers['X-Content-Digest'] = digest
response.headers['Content-Length'] = size.to_s unless response.headers['Transfer-Encoding']
- response.body = entity_store.open(digest)
+ response.body = entity_store.open(digest) || response.body
end
# read existing cache entries, remove non-varying, and add this one to
20 test/metastore_test.rb
View
@@ -182,6 +182,26 @@ def self.call(request); request.path_info.reverse end
@store.lookup(@request, @entity_store).should.be.nil
end
+ it 'gracefully degrades if the cache store stops working' do
+ @store = Class.new(Rack::Cache::MetaStore) do
+ def purge(*args); nil end
+ def read(*args); [] end
+ def write(*args); nil end
+ end.new
+ @entity_store = Class.new(Rack::Cache::EntityStore) do
+ def exists?(*args); false end
+ def open(*args); nil end
+ def read(*args); nil end
+ def write(*args); nil end
+ def purge(*args); nil end
+ end.new
+
+ request = mock_request('/test', {})
+ response = mock_response(200, {}, ['test'])
+ @store.store(request, response, @entity_store)
+ response.body.should == ['test']
+ end
+
# Vary =======================================================================
it 'does not return entries that Vary with #lookup' do
Please sign in to comment.
Something went wrong with that request. Please try again.