wp_cache_get_last_changed()
Gets last changed date for the specified cache group.
No Hooks.
Return
String
. UNIX timestamp with microseconds representing when the group was last changed.
Usage
wp_cache_get_last_changed( $group );
- $group(string) (required)
- Where the cache contents are grouped.
Examples
#1 Example of using time tags when creating a cache
A stripped down piece of code from the kernel, which is used in the get_pages() function to cache its results.
function some_cache_orientated_function(){ $key = md5( serialize( 'Some data, whatever' ) ); $last_changed = wp_cache_get_last_changed( 'posts' ); $cache_key = "get_pages:$key:$last_changed"; // get the cache $cache = wp_cache_get( $cache_key, 'posts' ); // there is a cache, let's bring it back if ( false !== $cache ) { return $pages; } $pages = $wpdb->get_results('SQL query for posts' ); // keep only the ID $page_structure = array(); foreach ( $pages as $page ) { $page_structure[] = $page->ID; } // no cache, get the data and save it in the cache wp_cache_set( $cache_key, $page_structure, 'posts' ); return $pages; }
Changelog
Since 4.7.0 | Introduced. |
wp_cache_get_last_changed() wp cache get last changed code WP 6.7.2
function wp_cache_get_last_changed( $group ) { $last_changed = wp_cache_get( 'last_changed', $group ); if ( $last_changed ) { return $last_changed; } return wp_cache_set_last_changed( $group ); }