I find myself working with a lot of Kirby projects that require calls to external APIs or feeds. This plugin is a simple helper function that adds a caching layer to
getCached($url, $expires = 3600);
The path for the request
Number of seconds until the cache expires (optional; defaults to 1 hour)
getCached() as a drop-in replacement for Kirby’s
f::read() or PHP’s
Did you know that you can use Kirby’s built-in cache for your custom data as well?
$cache = kirby()->cache()->get('your.cache.key');
if($cache) return $cache;
// get the value
kirby()->cache()->set('your.cache.key', $value, $minutes);
Of course the cache needs to be enabled for this to work.
Good to know.
This plugin actually works very well in cases where you don’t want to have the general cache enabled.
For example, advanced search queries where parameters are used to get a certain subset of feed data. In that case the same page/URL might be serving up different content on each page load – but
getCached() can cache individual request results.