-
Notifications
You must be signed in to change notification settings - Fork 5.5k
caching: Correctly calculate cached responses age #12802
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
Changes from 13 commits
244eeb5
f532e3a
c7d76a0
cbc94f1
8dd368b
0d8bcc9
25b5316
f2cf3e4
98adeb7
3e8ddb5
333efc1
334f7e5
57c59e9
c882a04
34b22a3
22c3ab6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -170,6 +170,16 @@ using LookupResultPtr = std::unique_ptr<LookupResult>; | |
| // TODO(toddmgreer): Ensure that stability guarantees above are accurate. | ||
| size_t stableHashKey(const Key& key); | ||
|
|
||
| // The metadata associated with a cached response. | ||
| // TODO(yosrym93): This could be changed to a proto if a need arises. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for now, yes. However, it's worth noting that if a persistent cache is created using this code, and then you change it to a proto, you'd need to somehow invalidate the entire cache when referenced by the new code. Maybe add that to the comment? Also how would we invalidate the cache? Would we put a version # into the key?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added this to the comment. As for the how, IIUC, cache invalidation will need to be implemented at some point in the future anyway.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the scenario where we need to invalidate everything, we would alter the key generation--if there isn't anything more situation-specific, we might add a version #. |
||
| struct ResponseMetadata { | ||
| // The time at which a response was was most recently inserted, updated, or validated in this | ||
| // cache. This represents "response_time" in the age header calculations at: | ||
| // https://httpwg.org/specs/rfc7234.html#age.calculations | ||
| SystemTime response_time_; | ||
| }; | ||
| using ResponseMetadataPtr = std::unique_ptr<ResponseMetadata>; | ||
|
yosrym93 marked this conversation as resolved.
Outdated
|
||
|
|
||
| // LookupRequest holds everything about a request that's needed to look for a | ||
| // response in a cache, to evaluate whether an entry from a cache is usable, and | ||
| // to determine what ranges are needed. | ||
|
|
@@ -191,16 +201,17 @@ class LookupRequest { | |
| // LookupHeadersCallback. Specifically, | ||
| // - LookupResult::cache_entry_status_ is set according to HTTP cache | ||
| // validation logic. | ||
| // - LookupResult::headers takes ownership of response_headers. | ||
| // - LookupResult::content_length == content_length. | ||
| // - LookupResult::response_ranges entries are satisfiable (as documented | ||
| // - LookupResult::headers_ takes ownership of response_headers. | ||
| // - LookupResult::content_length_ == content_length. | ||
| // - LookupResult::response_ranges_ entries are satisfiable (as documented | ||
| // there). | ||
| LookupResult makeLookupResult(Http::ResponseHeaderMapPtr&& response_headers, | ||
| uint64_t content_length) const; | ||
| ResponseMetadata&& metadata, uint64_t content_length) const; | ||
|
|
||
| private: | ||
| void initializeRequestCacheControl(const Http::RequestHeaderMap& request_headers); | ||
| bool requiresValidation(const Http::ResponseHeaderMap& response_headers) const; | ||
| bool requiresValidation(const Http::ResponseHeaderMap& response_headers, | ||
| SystemTime::duration age) const; | ||
|
|
||
| Key key_; | ||
| std::vector<RawByteRange> request_range_spec_; | ||
|
|
@@ -231,7 +242,8 @@ using InsertCallback = std::function<void(bool success_ready_for_more)>; | |
| class InsertContext { | ||
| public: | ||
| // Accepts response_headers for caching. Only called once. | ||
| virtual void insertHeaders(const Http::ResponseHeaderMap& response_headers, bool end_stream) PURE; | ||
| virtual void insertHeaders(const Http::ResponseHeaderMap& response_headers, | ||
| const ResponseMetadata& metadata, bool end_stream) PURE; | ||
|
|
||
| // The insertion is streamed into the cache in chunks whose size is determined | ||
| // by the client, but with a pace determined by the cache. To avoid streaming | ||
|
|
@@ -343,7 +355,8 @@ class HttpCache { | |
| // This is called when an expired cache entry is successfully validated, to | ||
| // update the cache entry. | ||
| virtual void updateHeaders(const LookupContext& lookup_context, | ||
| const Http::ResponseHeaderMap& response_headers) PURE; | ||
| const Http::ResponseHeaderMap& response_headers, | ||
| const ResponseMetadata& metadata) PURE; | ||
|
|
||
| // Returns statically known information about a cache. | ||
| virtual CacheInfo cacheInfo() const PURE; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.