Function: get_template_part_cached()

In my WordCamp Chicago presentation I had an bunk version of this function. Here’s a better version. Though we could probably still improve even this:

function get_template_part_cached($slug, $name, $key, $group = 'posts', $ttl = 3600) {
if( !$output = wp_cache_get($key, $group)) {
ob_start();
get_template_part($slug,$name);
$output = ob_get_contents();
ob_end_clean();
wp_cache_set( $key, $output, $group, $ttl );
}
echo $output;
}