Skip to content

Instantly share code, notes, and snippets.

@bolstad
Created June 4, 2013 16:07
Show Gist options
  • Save bolstad/5707180 to your computer and use it in GitHub Desktop.
Save bolstad/5707180 to your computer and use it in GitHub Desktop.
<?php
/**
* @package Cache Wrapper
* @version 1.0
*/
/*
Plugin Name: Cache Wrapper
Version: 1.0
*/
function hip_cache_wrapper()
{
if ($_GET[cached_json])
{
$request_uri = $_SERVER['REQUEST_URI'];
$modified_uri = 'http://' . $_SERVER['HTTP_HOST'] . str_replace('cached_json','json',$request_uri);
$cachekey = "jsoncachez-" . md5($modified_uri);
$result = wp_cache_get( $cachekey );
if ( false === $result )
{
$mela = wp_remote_get($modified_uri,array('timeout'=>600)) ;
$result = wp_remote_retrieve_body($mela );
wp_cache_set( $cachekey, $result );
}
print $result;
die;
}
}
add_action('init','hip_cache_wrapper');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment