Skip to content

Instantly share code, notes, and snippets.

@dsawardekar
Created August 22, 2017 05:48
Show Gist options
  • Save dsawardekar/4c4e75f3f1d2167ea2af588839713486 to your computer and use it in GitHub Desktop.
Save dsawardekar/4c4e75f3f1d2167ea2af588839713486 to your computer and use it in GitHub Desktop.
<?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