Make WordPress Core


Ignore:
Timestamp:
10/21/2016 02:53:19 AM (8 years ago)
Author:
jorbin
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/general-template.php

    r38826 r38849  
    17141714    $output = '';
    17151715
    1716     $last_changed = wp_cache_get( 'last_changed', 'posts' );
    1717     if ( ! $last_changed ) {
    1718         $last_changed = microtime();
    1719         wp_cache_set( 'last_changed', $last_changed, 'posts' );
    1720     }
     1716    $last_changed = wp_cache_get_last_changed( 'posts' );
    17211717
    17221718    $limit = $r['limit'];
Note: See TracChangeset for help on using the changeset viewer.