Created
August 22, 2017 05:48
-
-
Save dsawardekar/4c4e75f3f1d2167ea2af588839713486 to your computer and use it in GitHub Desktop.
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_temperature() { | |
// api call | |
} | |
function get_cached( $method, $args ) { | |
$key = [ $method, $args ]; | |
$key = md5( $key ); | |
$value = get_transient( $key ); | |
if ( $value === false ) { | |
$value = call_user_func( $method, $args ); | |
set_transient( $key, $value ); | |
} | |
return $value; | |
} | |
get_cached( 'get_temperature', 'foo' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment