code: public function getOutput(ItemInterface $item, $userId)
      {
          if ($item->getCacheTime()) {
              // Get Cache Item
              $cache = $this->cache->getItem($item->getId().$userId);
  
              // Set Cache Expires
              $cache->expiresAfter($item->getCacheTime());
  
              // Save
              if (false === $cache->isHit()) {
                  $cache->set($item->getTemplate() ? $this->engine->render($item->getTemplate(), ['widget' => $item]) : $item->getContent());
                  $this->cache->save($cache);
              }
  
              return $cache->get();
          }
  
          return $item->getTemplate() ? $this->engine->render($item->getTemplate(), ['widget' => $item]) : $item->getContent();
      }
docs: Get Widget Output for Cache.
  
  @param ItemInterface $item
  @param $userId
  
  @throws \Psr\Cache\InvalidArgumentException
  @throws \Twig_Error_Loader
  @throws \Twig_Error_Runtime
  @throws \Twig_Error_Syntax
  
  @return mixed|string