Last active
April 6, 2016 06:43
-
-
Save ville6000/2cb9d774f524e46d1a045d052e90ed4e to your computer and use it in GitHub Desktop.
Transients
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_my_expensive_data() { | |
$cache_key = 'my-cache-key'; | |
$transient = get_transient( $cache_key ); | |
if ( $transient ) { | |
return $transient; | |
} else { | |
$data = wp_remote_get( 'http://your-service.com' ); | |
set_transient( $cacke_key, $data, DAY_IN_SECONDS ); | |
return $data; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment