Skip to content

Instantly share code, notes, and snippets.

@magnum
Created April 19, 2023 15:00
Show Gist options
  • Save magnum/12d4f6ec05ebff38a057621676c0e224 to your computer and use it in GitHub Desktop.
Save magnum/12d4f6ec05ebff38a057621676c0e224 to your computer and use it in GitHub Desktop.
<?php
function cache_fetch($key, $group='', $callable, $expiration=0) {
$value = wp_cache_get($key, $group);
if(!$value) {
$value = $callable();
wp_cache_set($key, $value, $group, $expiration);
}
return $value;
}
cache_fetch("recent_post_ids", "", function() {
return "code tha calculates value(s) to cache";
}, 60 * 60 * 24);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment