HttpCache as a Client middleware #125
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What this PR does
Adds a
CacheMiddlewarethat makes the HTTP Client capable of first-class, on-disk HTTP caching. Supports:Cache-Control,Expires,Vary,ETag,Last-Modified,must-revalidate,s-maxage,max-age, and status-code semanticsWhy
Network latency is really painful when testing the Blueprints runner. With CacheMiddleware, the same Blueprint can be re-ran multiple times without waiting for the repeated downloads. It should also give the unit tests a large boost.
Implementation
CacheMiddlewareCache-Control,Expires,Vary,ETag,Last-Modified,must-revalidate,s-maxage,max-age, and status-code semantics.<cache_dir>/<sha1(url)>_<cache_key>.json<cache_dir>/<sha1(url)>_<cache_key>.bodyClientwiringcache_dir.CacheMiddleware → RedirectionMiddleware → HttpMiddleware.get_response()helper and exposesRequest::$cache_key.Request $request,array $options = [], etc.) and swaps someif(!is_array())boilerplate for short syntax.A few bug fixes caught on the way:
TcpServercould log undefined variables when the handler blew up; now initialises them and null-checks writes.TransportInterface, dead code inClientTestBaseremoved.Testing
Confirm CI Tests pass. One or two may be flaky on window but most runners should be green.