Skip to content

Instantly share code, notes, and snippets.

@tollmanz
Created May 16, 2012 08:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tollmanz/2708698 to your computer and use it in GitHub Desktop.
Save tollmanz/2708698 to your computer and use it in GitHub Desktop.
Caching with a "Backup"
<?php
function get_hottest_cities( $force = false ) {
$hottest_cities = get_transient( 'zdt-hottest-cities' );
if ( false === $hottest_cities || $force ) {
if ( $force ) {
$hottest_cities = retrieve_hottest_cities();
if ( $hottest_cities ) {
set_transient( 'zdt-hottest-cities', $hottest_cities );
if ( get_option( 'zdt-hottest-cities' ) )
update_option( 'zdt-hottest-cities', $hottest_cities );
else
add_option( 'zdt-hottest-cities', $hottest_cities, '', 'no' );
}
} else {
$backup = get_option( 'zdt-hottest-cities', array() );
set_transient( 'zdt-hottest-cities', $backup );
wp_schedule_single_event( time(), 'zdt_refresh_hottest_cities' );
}
}
return $hottest_cities;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment