Make theme.json related caches persistent#6289
Make theme.json related caches persistent#6289spacedmonkey wants to merge 1 commit intoWordPress:trunkfrom
Conversation
Cache handling methods in WP theme class have been updated from private to public enabling widespread use. Additional 'delete_theme_json_cache' method has been implemented to effectively manage cache deletion by focusing on keys saved in 'theme_json' cache group. Changes also include removal of 'theme_json' from non-persistent groups boosting cache persistence.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Unlinked AccountsThe following contributors have not linked their GitHub and WordPress.org accounts: @jonnynews. Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
joemcgill
left a comment
There was a problem hiding this comment.
Thanks @spacedmonkey, and thanks for your patience with reviewing this. I think the intent of this PR is right, but I don't think that making the WP_Theme object responsible for caching theme_json data is the right place to locate responsibility for these caches.
All of the places where the theme_json cache group is used, the data being cached is dependent on the final resolved WP_Theme_JSON object that merges data from core, all registered blocks, the active theme, and user data produced by the site editor. The exceptions are functions that are directly accessing WP_Theme_JSON_Resolver::get_theme_data(), which only cares about parsed theme_json data from the theme.
I think it would be better to locate caching for the underlying WP_Theme_JSON data in the WP_Theme_JSON_Resolver class. For all of the places in global core functions where we are currently caching to theme theme_json group, we're generally doing so to avoid recalculating some specific data from the merged WP_Theme_JSON object (e.g., WP_Theme_JSON_Resolver::get_merged_data())`.
Note that each of the four WP_Theme_JSON data sources get statically cached during each request as properties of the WP_Theme_JSON_Resolver object. We may not be able to persistently cache the final merged WP_Theme_JSON object, but it's possible that we could persistently cache one or more source (i.e. "origin") of WP_Theme_JSON data (e.g., the data from core and the currently active theme).
Make theme.json related caches persistent by reusing
cache_getandcache_addmethods in WP_Theme. This means that caches are only saved for 1800 seconds. Caches for theme json are invalidated for the following reason.Trac ticket: https://core.trac.wordpress.org/ticket/57789
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.