Classes/Traits/CacheTrait.php
protected function cacheViaTrait(string $entryIdentifier, callable $callback, string $cacheIdentifier, int $lifetime = 0, array $tags = [])
    {
        try {
            /** @var AbstractFrontend $cache */
            $cache = GeneralUtility::makeInstance(CacheManager::class)->getCache($cacheIdentifier);
        } catch (\Exception $ex) {
            $logger = GeneralUtility::makeInstance(LogManager::class)->getLogger(__CLASS__);
            $logger->error($ex->getMessage(), ['entryIdentifier' => $entryIdentifier, 'cacheIdentifier' => $cacheIdentifier]);

            return \call_user_func_array($callback, []);
        }

        // Do not use "has" because the cache is a shared resource
        $result = $cache->get($entryIdentifier);
        if (false !== $result) {
            return $result;
        }
        $result = \call_user_func_array($callback, []);
        $cache->set($entryIdentifier, $result, $tags, 0 === $lifetime ? null : $lifetime);

        return $result;
    }
protected function cacheViaTrait(string $entryIdentifier, callable $callback, string $cacheIdentifier, int $lifetime = 0, array $tags = [])
    {
        try {
            /** @var AbstractFrontend $cache */
            $cache = GeneralUtility::makeInstance(CacheManager::class)->getCache($cacheIdentifier);
        } catch (\Exception $ex) {
            $logger = GeneralUtility::makeInstance(LogManager::class)->getLogger(__CLASS__);
            $logger->error($ex->getMessage(), ['entryIdentifier' => $entryIdentifier, 'cacheIdentifier' => $cacheIdentifier]);

            return \call_user_func_array($callback, []);
        }

        // Do not use "has" because the cache is a shared resource
        $result = $cache->get($entryIdentifier);
        if (false !== $result) {
            return $result;
        }
        $result = \call_user_func_array($callback, []);
        $cache->set($entryIdentifier, $result, $tags, 0 === $lifetime ? null : $lifetime);

        return $result;
    }
protected function cacheViaTrait ( string $ entryIdentifier , callable $ callback , string $ cacheIdentifier , int $ lifetime = 0 , array $ tags = [ ] ) { try { /** @var AbstractFrontend $cache */ $ cache = GeneralUtility :: makeInstance ( CacheManager :: class ) -> getCache ( $ cacheIdentifier ) ; } catch ( \ Exception $ ex ) { $ logger = GeneralUtility :: makeInstance ( LogManager :: class ) -> getLogger ( __CLASS__ ) ; $ logger -> error ( $ ex -> getMessage ( ) , [ 'entryIdentifier' => $ entryIdentifier , 'cacheIdentifier' => $ cacheIdentifier ] ) ; return \ call_user_func_array ( $ callback , [ ] ) ; } // Do not use "has" because the cache is a shared resource $ result = $ cache -> get ( $ entryIdentifier ) ; if ( false !== $ result ) { return $ result ; } $ result = \ call_user_func_array ( $ callback , [ ] ) ; $ cache -> set ( $ entryIdentifier , $ result , $ tags , 0 === $ lifetime ? null : $ lifetime ) ; return $ result ; }
Cache via Trait logic.

@param string   $entryIdentifier
@param callable $callback
@param string   $cacheIdentifier
@param int      $lifetime
@param array    $tags

@return mixed
Cache via Trait logic .