Cache get_term_by() calls:

* Add a helper function, `wp_get_last_changed()`, to retrieve a last-modified timestamp by cache group
* When caching a term, also make cache entries for slug and name via `slug:{$term_id}` and `name:{$term_id}` keys in the `$taxonomy:$last_changed` bucket that reference the term_id
* In `clean_term_cache()` and `update_term_cache()`, respect `$_wp_suspend_cache_invalidation`
* Original term cache entries maintain BC

Adds unit tests.

Props wonderboymusic, tollmanz, boonebgorges.
Fixes #21760.


git-svn-id: https://develop.svn.wordpress.org/trunk@29915 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Scott Taylor
2014-10-16 04:44:13 +00:00
parent 076c7e8902
commit 0d58d32462
3 changed files with 184 additions and 15 deletions

View File

@@ -4629,3 +4629,21 @@ function wp_validate_boolean( $var ) {
return (bool) $var;
}
/**
* Helper function to retrieve an incrementer identified by $group
*
* @since 4.1.0
*
* @param string $group The cache group for the incrementer.
* @param bool $force Whether or not to generate a new incrementor.
* @return int The timestamp representing 'last_changed'.
*/
function wp_get_last_changed( $group, $force = false ) {
$last_changed = wp_cache_get( 'last_changed', $group );
if ( ! $last_changed || true === $force ) {
$last_changed = microtime();
wp_cache_set( 'last_changed', $last_changed, $group );
}
return $last_changed;
}