Refactor cache_filter to expect caches to post cb #36184
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.
Commit Message: Refactor cache_filter to expect caches to post cb
Additional Description: This is a bit of an unintuitive change in that it moves some work from the common class to the plugin, meaning that work will be duplicated. However, there's a good reason for this - if the cache class needs to use a dispatcher to get back onto its own thread, having cache_filter also post means that actions end up being queued in the dispatcher twice.
A different possible solution would be to have the cache_filter callbacks only post if the callback comes in on the wrong thread, but there's a wrinkle in that model too - if the callback executes immediately, on the same thread, as was the case with the simple_http_cache, it executes too soon, trying to resume a connection that hasn't yet stopped, which is an error. That, too, could be covered with another workaround, either intercepting when that happens and posting the resume, or intercepting when that happens and replacing the resume with returning
Continue
instead, but both of those options make the cache filter itself more complicated (and therefore error prone).Having just one consistent path, where the cache implementation always posts the callback (and never calls it if cancelled), and the cache always performs the callback outside of the initial call's context and on its own thread, is the least complexity, and avoids the performance impact of posting twice, at a cost of a bit more verbosity in the simple cache implementation.
This PR also wraps the UpdateHeadersCallback into a declared type, and makes it an
AnyInvocable
instead of astd::function
, which enforces that callbacks are called only once and that they're moved not copied, avoiding accidental performance drains.Risk Level: Low; WIP filter, existing tests still pass.
Testing: Existing tests should be covering all cases. Added tests to enforce that all cache implementations'
LookupContext
correctly posts callback actions, and correctly cancels calling the callback if the context is deleted before the post resolves.Docs Changes: Code-comments only.
Release Notes: Maybe?
Platform Specific Features: n/a