Proposal: Add CachePolicy interface to allow for custom cache behavior#17362
Proposal: Add CachePolicy interface to allow for custom cache behavior#17362jmarantz merged 9 commits intoenvoyproxy:mainfrom
Conversation
Signed-off-by: Josiah Kiehl <josiah@capoferro.net>
Signed-off-by: Josiah Kiehl <josiah@capoferro.net>
Signed-off-by: Josiah Kiehl <josiah@capoferro.net>
jmarantz
left a comment
There was a problem hiding this comment.
This is basically an RFC?
I assume you'll modify the caching interface to use the policy in its API?
| // createCacheKey calculates the lookup key for storing the entry in the cache. | ||
| virtual Key createCacheKey(const Envoy::Http::RequestHeaderMap& request_headers) PURE; | ||
|
|
||
| // requestCacheable modifies the cacheability of the response during |
There was a problem hiding this comment.
Use doxygen style comments for this interface. Based on the interface I think you mean to say:
/**
* @return whether the request is cacheable.
* /
Also should the method be const?
There was a problem hiding this comment.
I'm a bit wary of const at the interface level, as I don't want to inadvertently restrict what a custom CachePolicy implementation can do. That said, I personally have no plans to introduce anything that modifies CachePolicy in createCacheKey, requestCacheable, responseCacheable or computeCacheEntryUsability, and could add const to all 4 of those.
What do you think? Should I add const to all of the above?
Yeah, more or less. I want some feedback on the interface before I dive in and do the full integration. I have a version of everything implemented, across the CacheFilter, but it'll take some work to clean it up and port it to OSS Envoy, so having feedback on the interface before I do that work will make the process more efficient and make sure I'm implementing with a fully hashed out design. |
Signed-off-by: Josiah Kiehl <josiah@capoferro.net>
Signed-off-by: Josiah Kiehl <josiah@capoferro.net>
|
cc myself @penguingao |
penguingao
left a comment
There was a problem hiding this comment.
Could you clarify the commit message a bit? I think the part that needs some clarification is "Logic that provides RFC compliance for caching semantics. That belongs in CacheFilter and related utils."
My understanding is that CachePolicy is used to override RFC7234 behavior, but how is the RFC7234 behavior implemented? I'd naively think that the easiest way to abstract this is to have an Rfc7234CachePolicy implementation, which is used by default, and custom behaviors are introduced with an override of the CachePolicy interface. This seems to not comply with the commit message.
The idea is that the RFC behavior is provided in the CacheFilter and/or HttpCache base class and then the CachePolicy functions are called afterward to allow the custom, supplementary, logic to change the RFC-compliant result, if necessary. This does mean that if the CachePolicy intends to completely replace RFC behavior, then the RFC logic being run at all will be wasteful. For example, if we have a policy that forces caching of all content, then it doesn't matter what the RFC logic decides, we're going to decide to cache it anyway, and so we may as well not run the RFC logic. We certainly could contain all of the RFC compliant logic in an implementation of CachePolicy, I was just thinking it'd be better to have the CachePolicy be where exceptions to the rules live, rather than where the rules live. |
jmarantz
left a comment
There was a problem hiding this comment.
Will take another look once you address @penguingao 's comments
/wait
I would prefer to have the option to completely replace CachePolicy implementations by an extension. Exceptions are not rare when it comes to HTTP caching. As you said, it's wasteful to make the same decision twice in many cases. With CachePolicy just making all the decisions, it provides a cleaner interface (no need to parse cache-control and pass in - each CachePolicy can just do it inside if it cares about the header), and cleaner life cycle expectations on the interface (each function just determines the behavior, instead of overriding a previous result it does not have exposure to). Given no "default behavior", the CachePolicy extensions cannot decide what it is "modifying", meaning as soon as you have a CachePolicy extension written, it already has to make the full decision, not exceptions, because the current API does not provide the "default decision" into the methods. You could fix this by making the methods return a tuple of { bool override_decision, ResultType result} for each method, but it's rather messy. |
Ok, this makes sense to me. I've reworded the comments to reflect this, and will keep this in mind for the full integration into CachePolicy. |
Signed-off-by: Josiah Kiehl <josiah@capoferro.net>
|
@penguingao you good with this now? |
Yup, this LGTM now. |
jmarantz
left a comment
There was a problem hiding this comment.
/assign-from @envoyproxy/senior-maintainers
|
@envoyproxy/senior-maintainers assignee is @zuercher |
Signed-off-by: Josiah Kiehl <josiah@capoferro.net>
Signed-off-by: Josiah Kiehl <josiah@capoferro.net>
|
/retest |
|
Retrying Azure Pipelines: |
* main: (687 commits) ci: set build debug information from env (envoyproxy#17635) ext_authz: do the authentication even the direct response is set (envoyproxy#17546) upstream: various cleanups in connection pool code (envoyproxy#17644) owners: promote Dmitry to maintainer (envoyproxy#17642) quiche: client session supports creating bidi stream (envoyproxy#17543) Update HTTP/2 METADATA documentation. (envoyproxy#17637) ext_proc: Check validity of the :status header (envoyproxy#17596) test: add ASSERT indicating that gRPC stream has not been started yet (envoyproxy#17614) ensure that the inline cookie header will be folded correctly (envoyproxy#17560) cluster_manager: Make ClusterEntry a class instead of a struct (envoyproxy#17616) owners: make Raúl a Thrift senior extension maintainer (envoyproxy#17641) quiche: update QUICHE dependency (envoyproxy#17618) Delete mock for removed RouteEntry::perFilterConfig() method (envoyproxy#17623) REPO_LAYOUT.md: fix outdated link (envoyproxy#17626) hcm: forbid use of detection extensions with use_remote_addr/xff_num_trusted_hops (envoyproxy#17558) thrift proxy: add request shadowing support (envoyproxy#17544) ext_proc: Ensure that timer is always cancelled (envoyproxy#17569) Proposal: Add CachePolicy interface to allow for custom cache behavior (envoyproxy#17362) proto: fix verify to point at v3 only (envoyproxy#17622) api: move generic matcher proto to its own package (envoyproxy#17096) ...
* main: (687 commits) ci: set build debug information from env (envoyproxy#17635) ext_authz: do the authentication even the direct response is set (envoyproxy#17546) upstream: various cleanups in connection pool code (envoyproxy#17644) owners: promote Dmitry to maintainer (envoyproxy#17642) quiche: client session supports creating bidi stream (envoyproxy#17543) Update HTTP/2 METADATA documentation. (envoyproxy#17637) ext_proc: Check validity of the :status header (envoyproxy#17596) test: add ASSERT indicating that gRPC stream has not been started yet (envoyproxy#17614) ensure that the inline cookie header will be folded correctly (envoyproxy#17560) cluster_manager: Make ClusterEntry a class instead of a struct (envoyproxy#17616) owners: make Raúl a Thrift senior extension maintainer (envoyproxy#17641) quiche: update QUICHE dependency (envoyproxy#17618) Delete mock for removed RouteEntry::perFilterConfig() method (envoyproxy#17623) REPO_LAYOUT.md: fix outdated link (envoyproxy#17626) hcm: forbid use of detection extensions with use_remote_addr/xff_num_trusted_hops (envoyproxy#17558) thrift proxy: add request shadowing support (envoyproxy#17544) ext_proc: Ensure that timer is always cancelled (envoyproxy#17569) Proposal: Add CachePolicy interface to allow for custom cache behavior (envoyproxy#17362) proto: fix verify to point at v3 only (envoyproxy#17622) api: move generic matcher proto to its own package (envoyproxy#17096) ... Signed-off-by: Michael Puncel <mpuncel@squareup.com>
envoyproxy#17362) Commit Message: Add CachePolicy interface Additional Description: In order to support custom cache behavior, we need to provide an extension point that allows the results of basic cache semantics to be modified prior to acting on the calculated results. A CachePolicy implementation contains logic that modifies how the CacheFilter interacts with an implementation of HttpCache. This includes key generation, cacheability and cache entry usability concerns. A CachePolicy implementation does not contain: Logic that handles encoding or decoding a request or response. That belongs in CacheFilter. Logic specific to a cache. That belongs in HttpCache and related utils. After we agree on the interface, I'll follow this PR with CachePolicyImpl and full integration in the CacheFilter. Risk Level: None. Code is not in use. Signed-off-by: Josiah Kiehl <josiah@capoferro.net>
Commit Message:
Add CachePolicy interface
Additional Description:
In order to support custom cache behavior, we need to provide an extension point that allows the results of basic cache semantics to be modified prior to acting on the calculated results.
A CachePolicy implementation contains logic that modifies how the CacheFilter interacts with an implementation of HttpCache. This includes key generation, cacheability and cache entry usability concerns.
A CachePolicy implementation does not contain:
After we agree on the interface, I'll follow this PR with CachePolicyImpl and full integration in the CacheFilter.
Risk Level: None. Code is not in use.