Skip to content

Instantly share code, notes, and snippets.

@tollmanz
Created October 13, 2012 00:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tollmanz/3882524 to your computer and use it in GitHub Desktop.
Save tollmanz/3882524 to your computer and use it in GitHub Desktop.
Basic Incrementor/Versioning Pattern
<?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