Skip to content

Make theme.json related caches persistent#6289

Open
spacedmonkey wants to merge 1 commit intoWordPress:trunkfrom
spacedmonkey:fix/theme-caching
Open

Make theme.json related caches persistent#6289
spacedmonkey wants to merge 1 commit intoWordPress:trunkfrom
spacedmonkey:fix/theme-caching

Conversation

@spacedmonkey
Copy link
Copy Markdown
Member

Make theme.json related caches persistent by reusing cache_get and cache_add methods in WP_Theme. This means that caches are only saved for 1800 seconds. Caches for theme json are invalidated for the following reason.

  • WP_Theme::cache_delete is called. Which is called when themes are updated, files edited or theme is deleted.
  • Global style post is updated.
  • Theme is switched or previewed.
  • Invalidated after 1800 seconds like other theme caches.

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.

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.
@github-actions
Copy link
Copy Markdown

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 props-bot label.

Unlinked Accounts

The 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.

@github-actions
Copy link
Copy Markdown

Test using WordPress Playground

The 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

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

Copy link
Copy Markdown
Member

@joemcgill joemcgill left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants