mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-28 14:20:15 +00:00
Cache API: Add helper function wp_cache_set_last_changed.
Add a helper function called `wp_cache_set_last_changed` to set the last changed value for cache groups. This function has a new action called `wp_cache_set_last_changed`, allowing for developers to cache invalidate when last changed value is changed. Props tillkruess, spacedmonkey, peterwilsoncc, mukesh27, johnjamesjacoby. Fixes #57905. git-svn-id: https://develop.svn.wordpress.org/trunk@55702 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -7680,12 +7680,42 @@ function wp_unique_id( $prefix = '' ) {
|
||||
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 );
|
||||
if ( $last_changed ) {
|
||||
return $last_changed;
|
||||
}
|
||||
|
||||
return $last_changed;
|
||||
return wp_cache_set_last_changed( $group );
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets last changed date for the specified cache group to now.
|
||||
*
|
||||
* @since 6.3.0
|
||||
*
|
||||
* @param string $group Where the cache contents are grouped.
|
||||
* @return string UNIX timestamp when the group was last changed.
|
||||
*/
|
||||
function wp_cache_set_last_changed( $group ) {
|
||||
$previous_time = wp_cache_get( 'last_changed', $group );
|
||||
|
||||
$time = microtime();
|
||||
|
||||
wp_cache_set( 'last_changed', $time, $group );
|
||||
|
||||
/**
|
||||
* Fires after a cache group `last_changed` time is updated.
|
||||
* This may occur multiple times per page load and registered
|
||||
* actions must be performant.
|
||||
*
|
||||
* @since 6.3.0
|
||||
*
|
||||
* @param string $group The cache group name.
|
||||
* @param int $time The new last changed time.
|
||||
* @param int|false $previous_time The previous last changed time. False if not previously set.
|
||||
*/
|
||||
do_action( 'wp_cache_set_last_changed', $group, $time, $previous_time );
|
||||
|
||||
return $time;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user