Opened 5 months ago
Last modified 5 months ago
#63618 new defect (bug)
`is_object_in_term` object cache uses "set" instead of "add"
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Awaiting Review | Priority: | normal |
| Severity: | normal | Version: | trunk |
| Component: | Cache API | Keywords: | has-patch |
| Focuses: | Cc: |
Description
is_object_in_term should respect [wp_suspend_cache_addition](https://developer.wordpress.org/reference/functions/wp_suspend_cache_addition/) and use wp_cache_add instead of wp_cache_set as in [get_the_terms](https://github.com/WordPress/WordPress/blob/c6041fd40a9d499a5d602be791349068699ef695/wp-includes/category-template.php#L1297-L1303)
Blamed line: https://github.com/WordPress/WordPress/blob/c6041fd40a9d499a5d602be791349068699ef695/wp-includes/taxonomy.php#L4895
I stumbled upon this building a long running WP-CLI command and noticed a memory leak issue while having object cache suspended. Turns out I had a has_category that filled the whole cache with category_relationships keys.
Change History (2)
This ticket was mentioned in PR #9054 on WordPress/wordpress-develop by @nlemoine.
5 months ago
#2
- Keywords has-patch added
Use wp_cache_add instead of wp_cache_set to prevent cache additions when wp_suspend_cache_addition has been set to true.
Additional note: term relationships caching is used in multiple functions:
The same code pattern is reused in multiple locations. It may need a central place for handling terms caching.