Created
May 16, 2012 08:28
-
-
Save tollmanz/2708698 to your computer and use it in GitHub Desktop.
Caching with a "Backup"
This file contains hidden or 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_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