Kevin
Well-known member
Using the example from @Jeremy P in this post about using the Symfony cache with XF 2.3, if we are using a callback to get the results if the cache key is not present or expired, do we need to explicitly save the item to cache in the callback function? Or do we need to do a 'getIem' & 'isHit' in combination with the callback? 
In the quick test below, I'm always hitting the callback and am never hitting the cached copy.

In the quick test below, I'm always hitting the callback and am never hitting the cached copy.
Code:
$cacheKey = 'cinvin.testwidget';
$cache = \XF::app()->cache('', true, false);
if ($cache)
{
$widgetRendered = $cache->get(
$cacheKey,
function (\Symfony\Contracts\Cache\ItemInterface $item): string
{
$item->expiresAfter(3600); // TTL
$widgetRendered = $this->getWidgetRendered();
return $widgetRendered;
}
);
}
else
{
return $this->getWidgetRendered();
}