public static function remember($key, $seconds, Closure $callback, $initDir = '/', $basedir = 'cache')
    {
        $debug = \Bitrix\Main\Data\Cache::getShowCacheStat();

        if ($seconds <= 0) {
            try {
                $result = $callback();
            } catch (AbortCacheException $e) {
                $result = null;
            }

            if ($debug) {
                CacheDebugger::track('zero_ttl', $initDir, $basedir, $key, $result);
            }

            return $result;
        }

        $obCache = new CPHPCache();
        if ($obCache->InitCache($seconds, $key, $initDir, $basedir)) {
            $vars = $obCache->GetVars();

            if ($debug) {
                CacheDebugger::track('hits', $initDir, $basedir, $key, $vars['cache']);
            }

            return $vars['cache'];
        }

        $obCache->StartDataCache();
        try {
            $cache = $callback();
            $obCache->EndDataCache(['cache' => $cache]);
        } catch (AbortCacheException $e) {
            $obCache->AbortDataCache();
            $cache = null;
        }

        if ($debug) {
            CacheDebugger::track('misses', $initDir, $basedir, $key, $cache);
        }

        return $cache;
    }
public static function remember($key, $seconds, Closure $callback, $initDir = '/', $basedir = 'cache')
    {
        $debug = \Bitrix\Main\Data\Cache::getShowCacheStat();

        if ($seconds <= 0) {
            try {
                $result = $callback();
            } catch (AbortCacheException $e) {
                $result = null;
            }

            if ($debug) {
                CacheDebugger::track('zero_ttl', $initDir, $basedir, $key, $result);
            }

            return $result;
        }

        $obCache = new CPHPCache();
        if ($obCache->InitCache($seconds, $key, $initDir, $basedir)) {
            $vars = $obCache->GetVars();

            if ($debug) {
                CacheDebugger::track('hits', $initDir, $basedir, $key, $vars['cache']);
            }

            return $vars['cache'];
        }

        $obCache->StartDataCache();
        try {
            $cache = $callback();
            $obCache->EndDataCache(['cache' => $cache]);
        } catch (AbortCacheException $e) {
            $obCache->AbortDataCache();
            $cache = null;
        }

        if ($debug) {
            CacheDebugger::track('misses', $initDir, $basedir, $key, $cache);
        }

        return $cache;
    }
public static function remember ( $ key , $ seconds , Closure $ callback , $ initDir = '/' , $ basedir = 'cache' ) { $ debug = \ Bitrix \ Main \ Data \ Cache :: getShowCacheStat ( ) ; if ( $ seconds <= 0 ) { try { $ result = $ callback ( ) ; } catch ( AbortCacheException $ e ) { $ result = null ; } if ( $ debug ) { CacheDebugger :: track ( 'zero_ttl' , $ initDir , $ basedir , $ key , $ result ) ; } return $ result ; } $ obCache = new CPHPCache ( ) ; if ( $ obCache -> InitCache ( $ seconds , $ key , $ initDir , $ basedir ) ) { $ vars = $ obCache -> GetVars ( ) ; if ( $ debug ) { CacheDebugger :: track ( 'hits' , $ initDir , $ basedir , $ key , $ vars [ 'cache' ] ) ; } return $ vars [ 'cache' ] ; } $ obCache -> StartDataCache ( ) ; try { $ cache = $ callback ( ) ; $ obCache -> EndDataCache ( [ 'cache' => $ cache ] ) ; } catch ( AbortCacheException $ e ) { $ obCache -> AbortDataCache ( ) ; $ cache = null ; } if ( $ debug ) { CacheDebugger :: track ( 'misses' , $ initDir , $ basedir , $ key , $ cache ) ; } return $ cache ; }
Store closure's result in the cache for a given number of seconds.

@param string $key
@param int $seconds
@param Closure $callback
@param bool|string $initDir
@param string $basedir
@return mixed
Store closure s result in the cache for a given number of seconds .