mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-04-11 08:04:32 +00:00
Cache API: introduce wp_cache_get_last_changed to improve DRY
One thing fairly common to the cache groups is a block of code to look to see when the cache was last changed, and if there isn't one, to set it for the current microtime(). It appears in 8 different places in core. This adds a new helper `wp_cache_get_last_changed` to DRY things up a bit. Since `wp-includes/cache.php` isn't guaranteed to be loaded, this new function is in `wp-includes/functions.php` Props spacedmonkey, desrosj. Fixes #37464. git-svn-id: https://develop.svn.wordpress.org/trunk@38849 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -5553,3 +5553,23 @@ function wp_generate_uuid4() {
|
||||
mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get last changed date for the specified cache group.
|
||||
*
|
||||
* @since 4.7.0
|
||||
*
|
||||
* @param $group Where the cache contents are grouped.
|
||||
*
|
||||
* @return string $last_changed UNIX timestamp with microseconds representing when the group was last changed.
|
||||
*/
|
||||
function wp_cache_get_last_changed( $group ) {
|
||||
$last_changed = wp_cache_get( 'last_changed', $group );
|
||||
|
||||
if ( ! $last_changed ) {
|
||||
$last_changed = microtime();
|
||||
wp_cache_set( 'last_changed', $last_changed, $group );
|
||||
}
|
||||
|
||||
return $last_changed;
|
||||
}
|
||||
Reference in New Issue
Block a user