Wordpress helper: cacheman
<?php
/**
* cacheman
*
* @author JoseRobinson.com
* @link https://gist.github.com/jrobinsonc/832f287b69fa3bfdd6f475fa33122edf
* @version 1.2.0
* @param string $key
* @param callable $callback
* @param int $expire - Optional
* @return mixed
*/
function cacheman($key, $callback = null, $expire = YEAR_IN_SECONDS)
{
$group = 'general';
if (false !== strpos($key, '.')) {
list($group, $key) = explode('.', $key);
}
$data = wp_cache_get( $key, $group );
if (false === $data && is_callable($callback)) {
$data = $callback();
wp_cache_set( $key, $data, $group, $expire );
}
return $data;
}