Repository navigation
Conversation
computed key, per-status durations, forget() by generation; the trait declares it
Contributor
|
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
Contributor
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 Follow this PR Review Process:
If you have questions about anything, reach out in #jetpack-developers for guidance! |
…-request-read-cache
phan flags a statement repeated on the next line
This branch has not been deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes CONNECT-496. Built on #53154, which this PR targets until it merges.
Proposed changes
Proxy_Requestcan now cache a read.The consumer declares the cache and the forward runs it, so the key is built in one place.
The
cacheargumentto_path()andto_site()takecache, off by default:prefix: the consumer's transient prefix.successanderror: seconds a response stays cached, by status below or from400. Each one is opt-in.bypass: skips the cached response and stores the fresh one.Only a
GETis cached.The connection check runs before the cache is read, so a site or a user without a token gets no cached data.
The key
It is computed, never supplied: path, query in any order, version, base, token context, the user id when the request is signed as the user, and the prefix's generation.
Proxy_Request::forget( $prefix )renews the generation, so every read under the prefix misses.The generation is a token in a non-autoloaded option.
The trait
WPCOM_REST_API_Proxy_Requestgets three properties,$cache_prefix,$cache_duration_success, and$cache_duration_error, which default to''and0.A consumer sets them in its constructor: PHP refuses a class that redeclares a trait property with another default.
A call overrides them through
$request_options['cache'], andfalseturns the cache off for that call.No existing consumer changes: without a prefix, nothing is cached.
Decisions to review
status,bodyas a string, andheaders), so the trait decodes on every call, hit or miss.WP_Error) is never cached. Only a wpcom response is.delete_expired_transients. A consumer with many distinct keys can add its prefix tojetpack_stats_transient_cleanup_prefixes.Related product discussion/links
Does this pull request change what data or activity we track or use?
No.
Testing instructions
Both suites are green.
Proxy_Request_Testcovers the key (path, query order, version, context, and user), the durations by status,bypass,forget(), and the trait's properties with their per-call override.