Make WordPress Core

Opened 15 months ago

Last modified 15 months ago

#55999 new defect (bug)

wp_suspend_cache_addition should also disable cache setting?

Reported by: malthert's profile malthert Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Cache API Keywords: has-patch needs-unit-tests 2nd-opinion
Focuses: performance Cc:


Right now wp_suspend_cache_addition is only checked when "add" to cache.

However most plugins/developers only use wp_cache_set for updating/adding to the cache.
This means in most plugins/cases, wp_suspend_cache_addition has no use, in fact it's rather unexpected behavior that only some functions can add to cache (namely: set, incr, decr)

I propose we also check wp_suspend_cache_addition before setting the cache.
This would also be in line with its function description:

Stops more data being added to the cache, but still allows cache retrieval.

As "set" also "adds" (or at least modifies if already exists therefore adds/subtracts) data in cache.

Change History (2)

This ticket was mentioned in PR #2824 on WordPress/wordpress-develop by kkmuffme.

15 months ago

  • Keywords has-patch added

#2 @johnbillion
15 months ago

  • Focuses performance added
  • Keywords needs-unit-tests 2nd-opinion added
  • Version trunk deleted

This is a good idea but it is a breaking change. During a large import for example, suspending cache addition makes sense to avoid consuming a large amount of memory (particularly when inserting terms and post meta), but updating existing cache entries may well be desirable and expected.

I'll see if I can find some concrete examples.

I think to avoid backwards compatibility issues this needs to be implemented via a new function such as wp_suspend_cache_changes().

Either way, it would be good to get test coverage on this too.

Note: See TracTickets for help on using tickets.