-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Proposal: Add CachePolicy interface to allow for custom cache behavior #17362
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a7dd6fd
Add CachePolicy interface
capoferro 193385c
Add CachePolicyCallbacks
capoferro a60636a
Fix BUILD
capoferro 5bf9821
Fix format
capoferro 2a82af3
Remove Envoy:: qualifiers
capoferro 7e5c6a5
Doxygen comments
capoferro 7e91633
CachePolicy comment updates
capoferro d8acb03
Fix parameter name
capoferro 891e87c
Fix format
capoferro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| #pragma once | ||
|
|
||
| #include "envoy/http/header_map.h" | ||
| #include "envoy/stream_info/filter_state.h" | ||
|
|
||
| #include "source/extensions/filters/http/cache/cache_headers_utils.h" | ||
| #include "source/extensions/filters/http/cache/http_cache.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Extensions { | ||
| namespace HttpFilters { | ||
| namespace Cache { | ||
|
|
||
| /** | ||
| * Contains information about whether the cache entry is usable. | ||
| */ | ||
| struct CacheEntryUsability { | ||
| /** | ||
| * Whether the cache entry is usable, additional checks are required to be usable, or unusable. | ||
| */ | ||
| CacheEntryStatus status = CacheEntryStatus::Unusable; | ||
| /** | ||
| * Value to be put in the Age header for cache responses. | ||
| */ | ||
| Seconds age = Seconds::max(); | ||
| }; | ||
|
|
||
| class CachePolicyCallbacks { | ||
| public: | ||
| virtual ~CachePolicyCallbacks() = default; | ||
|
|
||
| virtual const StreamInfo::FilterStateSharedPtr& filterState() PURE; | ||
| }; | ||
|
|
||
| /** | ||
| * An extension point for deployment specific caching behavior. | ||
| */ | ||
| class CachePolicy { | ||
| public: | ||
| virtual ~CachePolicy() = default; | ||
|
|
||
| /** | ||
| * Calculates the lookup key for storing the entry in the cache. | ||
| * @param request_headers - headers from the request the CacheFilter is currently processing. | ||
| */ | ||
| virtual Key createCacheKey(const Http::RequestHeaderMap& request_headers) PURE; | ||
|
|
||
| /** | ||
| * Determines the cacheability of the response during decoding. | ||
| * @param request_headers - headers from the request the CacheFilter is currently processing. | ||
| * @param request_cache_control - the result of parsing the request's Cache-Control header, parsed | ||
| * by the caller. | ||
| * @return true if the response may be cached, based on the contents of the request. | ||
| */ | ||
| virtual bool requestCacheable(const Http::RequestHeaderMap& request_headers, | ||
| const RequestCacheControl& request_cache_control) PURE; | ||
|
|
||
| /** | ||
| * Determines the cacheability of the response during encoding. | ||
| * @param request_headers - headers from the request the CacheFilter is currently processing. | ||
capoferro marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| * @param response_headers - headers from the upstream response the CacheFilter is currently | ||
| * processing. | ||
| * @param response_cache_control - the result of parsing the response's Cache-Control header, | ||
| * parsed by the caller. | ||
| * @param vary_allow_list - list of headers that the cache will respect when creating the Key for | ||
| * Vary-differentiated responses. | ||
| * @return true if the response may be cached. | ||
| */ | ||
| virtual bool responseCacheable(const Http::RequestHeaderMap& request_headers, | ||
| const Http::ResponseHeaderMap& response_headers, | ||
| const ResponseCacheControl& response_cache_control, | ||
| const VaryHeader& vary_allow_list) PURE; | ||
|
|
||
| /** | ||
| * Determines whether the cached entry may be used directly or must be validated with upstream. | ||
| * @param request_headers - request headers associated with the response_headers. | ||
| * @param cached_response_headers - headers from the cached response. | ||
| * @param request_cache_control - the parsed result of the request's Cache-Control header, parsed | ||
| * by the caller. | ||
| * @param cached_response_cache_control - the parsed result of the response's Cache-Control | ||
| * header, parsed by the caller. | ||
| * @param content_length - the byte length of the cached content. | ||
| * @param cached_metadata - the metadata that has been stored along side the cached entry. | ||
| * @param now - the timestamp for this request. | ||
| * @return details about whether or not the cached entry can be used. | ||
| */ | ||
| virtual CacheEntryUsability | ||
| computeCacheEntryUsability(const Http::RequestHeaderMap& request_headers, | ||
| const Http::ResponseHeaderMap& cached_response_headers, | ||
| const RequestCacheControl& request_cache_control, | ||
capoferro marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const ResponseCacheControl& cached_response_cache_control, | ||
| const uint64_t content_length, const ResponseMetadata& cached_metadata, | ||
| SystemTime now) PURE; | ||
|
|
||
| /** | ||
| * Performs actions when StreamInfo and FilterState become available, for | ||
| * example for logging and observability, or to adapt CacheFilter behavior based on | ||
| * route-specific CacheFilter config. | ||
| * @param callbacks - Gives access to StreamInfo and FilterState | ||
| */ | ||
| virtual void setCallbacks(CachePolicyCallbacks& callbacks) PURE; | ||
| }; | ||
|
|
||
| } // namespace Cache | ||
| } // namespace HttpFilters | ||
| } // namespace Extensions | ||
| } // namespace Envoy | ||
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.
Uh oh!
There was an error while loading. Please reload this page.