Jarves\Cache\ResponseCacher::renderCached PHP Method

renderCached() public method

In this cache method, the template engine is always called. If you want to cache this as well, use renderFullCached(). Example: return $this->renderCache('myCache', 'plugin1/default.tpl', function(){ return array('items' => heavyDbQuery()); }); Note: The $data callable is only called if the cache needs to regenerate (when it has been invalidated or empty, or the view file changed). If the callable $data returns NULL, then this will return NULL, too.
See also: method `render` to get more information.
public renderCached ( string $cacheKey, string $view, array | callable $data = null ) : string
$cacheKey string
$view string
$data array | callable Pass the data as array or a data provider function.
return string
    public function renderCached($cacheKey, $view, $data = null)
    {
        $cache = $this->cacher->getDistributedCache($cacheKey);
        $mTime = $this->getViewMTime($view);
        if (!$cache || !$cache['data'] || !is_array($cache) || $mTime != $cache['fileMTime']) {
            $data2 = $data;
            if (is_callable($data)) {
                $data2 = call_user_func($data, $view);
                if ($data2 === null) {
                    return null;
                }
            }
            $cache = array('data' => $data2, 'fileMTime' => $mTime);
            $this->cacher->setDistributedCache($cacheKey, $cache);
        }
        return $this->pageResponseFactory->createPluginResponse($this->templating->render($view, $cache['data']));
    }