Created
October 13, 2012 00:23
-
-
Save tollmanz/3882524 to your computer and use it in GitHub Desktop.
Basic Incrementor/Versioning Pattern
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function get_object( $force = false ) { | |
$cache_key = 'my-object-' . get_incrementor(); | |
$object = wp_cache_get( $cache_key ); | |
if ( false === $object ) { | |
$object = regenerate_cached_object(); | |
wp_cache_set( $cache_key, $object, 3600 ); | |
} | |
return $object; | |
} | |
function get_incrementor( $refresh = false ) { | |
$incrementor_key = 'my-incrementor'; | |
$incrementor_value = wp_cache_get( $incrementor_key ); | |
if ( false === $incrementor_value || true === $refresh ) { | |
$incrementor_value = time(); | |
wp_cache_set( $incrementor_key, $incrementor_value ); | |
} | |
return $incrementor_value; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment