From acfcea4cba52520b4b9f352dac83addca5aa1f1e Mon Sep 17 00:00:00 2001 From: Jonny Harris Date: Thu, 3 Feb 2022 17:41:46 +0000 Subject: [PATCH] Taxonomy: Remove cache expiry limitation in WP_Term_Query. Remove the one day expiry limitation from query caches found in the `WP_Term_Qurery` class. Removing this limitation means that the caches will remain in object caching, as long as possible. Ensure that all term / taxonomy cache clear functions invalidate query caches, by deleting the last_changed value in the terms cache group. Props spacedmonkey, adamsilverstein, boonebgorges, tillkruess, dlh, flixos90. Fixes #54511. git-svn-id: https://develop.svn.wordpress.org/trunk@52669 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/class-wp-term-query.php | 4 ++-- src/wp-includes/taxonomy.php | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/class-wp-term-query.php b/src/wp-includes/class-wp-term-query.php index 226c623c9f..1583ed6ab6 100644 --- a/src/wp-includes/class-wp-term-query.php +++ b/src/wp-includes/class-wp-term-query.php @@ -775,7 +775,7 @@ class WP_Term_Query { } if ( empty( $terms ) ) { - wp_cache_add( $cache_key, array(), 'terms', DAY_IN_SECONDS ); + wp_cache_add( $cache_key, array(), 'terms' ); return array(); } @@ -880,7 +880,7 @@ class WP_Term_Query { } } - wp_cache_add( $cache_key, $terms, 'terms', DAY_IN_SECONDS ); + wp_cache_add( $cache_key, $terms, 'terms' ); if ( 'all' === $_fields || 'all_with_object_id' === $_fields ) { $terms = $this->populate_terms( $terms ); diff --git a/src/wp-includes/taxonomy.php b/src/wp-includes/taxonomy.php index fbfef11ce8..201864cbc1 100644 --- a/src/wp-includes/taxonomy.php +++ b/src/wp-includes/taxonomy.php @@ -3518,6 +3518,8 @@ function clean_object_term_cache( $object_ids, $object_type ) { } } + wp_cache_delete( 'last_changed', 'terms' ); + /** * Fires after the object term cache has been cleaned. * @@ -3610,6 +3612,7 @@ function clean_term_cache( $ids, $taxonomy = '', $clean_taxonomy = true ) { function clean_taxonomy_cache( $taxonomy ) { wp_cache_delete( 'all_ids', $taxonomy ); wp_cache_delete( 'get', $taxonomy ); + wp_cache_delete( 'last_changed', 'terms' ); // Regenerate cached hierarchy. delete_option( "{$taxonomy}_children" );