Make WordPress Core

Opened 3 years ago

Last modified 4 months ago

#55780 new enhancement

Global Styles: Introduce filter for toggling stylesheet cache

Reported by: tyxla's profile tyxla Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 5.9
Component: Editor Keywords: has-patch
Focuses: multisite, performance Cc:

Description

Currently, for wp_get_global_stylesheet() and wp_get_global_styles_svg_filters() we'll cache the merged stylesheet data per theme in a transient for a minute if:

  • WP_DEBUG is not enabled;
  • SCRIPT_DEBUG is not enabled;
  • This is not a REST API request
  • We're not in the admin

However, for huge multisite instances that leverage object caching, this can result in thousands of wp_cache_set() operations per minute, which can be quite intensive.

At the same time, retrieving the global stylesheet data and merging it, on a well-optimized server will usually take very little time (up to a few milliseconds).

As a consequence, we end up wanting to disable that caching, because it creates more problems than it solves. However, there is no good trigger for disabling just that cache.

I'd like to propose a filter that allows us to disable the global stylesheet cache. While it will still be enabled by default, disabling it will be easy when needed.

Change History (8)

This ticket was mentioned in PR #2732 on WordPress/wordpress-develop by tyxla.


3 years ago
#1

  • Keywords has-patch added

#2 @costdev
3 years ago

  • Version changed from trunk to 5.9

#3 @tyxla
3 years ago

Note: the change seems pretty trivial, which is why I didn't add a unit test. It feels like testing this would fall down to testing whether apply_filters() work, which is redundant.

I'm happy to add a test or two if y'all feel differently about this.

#4 @costdev
3 years ago

  • Type changed from defect (bug) to enhancement

@oandregal commented on PR #2732:


2 years ago
#5

:wave: I wanted to cross-post that I commented at https://github.com/WordPress/gutenberg/pull/41201#issuecomment-1303111763 so it's not missed.

@oandregal commented on PR #2732:


2 years ago
#6

Cross-posting here as well:

Miguel has prepared https://github.com/WordPress/gutenberg/pull/45679 I think is very promising and should cover all cache invalidation we need. We only need to fix the automated tests.

#8 @pbearne
4 months ago

Does the Gutenberg patch fix the old style stylesheet

Looking at the patches I don't think it does so I feel the patch is still valid.

Happy to add tests if needed

Note: See TracTickets for help on using tickets.