Garbage collect expired cache data

@return  boolean  True on success, false otherwise.
961198
public function gc()
	{
		$this->engine->setOption('automaticCleaningFactor', 1);
		$this->engine->setOption('hashedDirectoryLevel', 1);

		$success1 = $this->engine->clean($this->directory . DS, false, 'old');

		if (!($dh = opendir($this->directory . DS)))
		{
			return false;
		}

		$result = true;

		while ($file = readdir($dh))
		{
			if ($file != '.' && $file != '..' && $file != '.svn')
			{
				$file2 = $this->directory . DS . $file;

				if (is_dir($file2))
				{
					$result = ($result and $this->engine->clean($file2 . DS, false, 'old'));
				}
			}
		}

		$success = ($success1 && $result);

		return $success;
	}
1337046
public function flush() {
		$pattern = $this->getCachePath() . DIRECTORY_SEPARATOR . $this->prefix . '_*';
		
		if (self::isExecAvailable()) {
			exec('rm ' . $pattern);
			return true;
		}
		
		$list = glob($pattern);
		
		if ($list === false) {
			return false;
		}
		
		if (empty($list)) {
			return true;
		}
		
		$result = true;
		
		foreach ($list as $path) {
			if (! unlink($path)) {
				$result = false;
			}
		}
		
		return $result;
	}
173513
public function gc_session($max)
    {
        $old = time() - $max;
        $this->where('access', '<', $old)->trash();

        return true;
    }
842620
private function cache()
	{
		if (!$this->cache)
		{
			return false;
		}

		// get developer params to get cache expiration
		if (App::has('component'))
		{
			$developerParams = App::get('component')->params('com_developer');
		}
		else
		{
			$developerParams = new \Hubzero\Config\Registry();
		}
		$cacheExpiration = $developerParams->get('doc_expiration', 720);

		// cache file
		$cacheFile = PATH_APP . DS . 'cache' . DS . 'api' . DS . 'documentation.json';

		// check if we have a cache file 
		if (file_exists($cacheFile))
		{
			// check if its still valid
			$cacheMakeTime = @filemtime($cacheFile);
			if (time() - $cacheExpiration < $cacheMakeTime)
			{
				$this->output = json_decode(file_get_contents($cacheFile), true);
				return true;
			}
		}

		return false;
	}
19071
public function removeIfExpired()
    {
        if ($this->getIsExpired() && !$this->getIsNewRecord()) {
            if (($this->expiredRemovingCallback instanceof Closure || is_array($this->expiredRemovingCallback)) && is_callable($this->expiredRemovingCallback)) {
                call_user_func($this->expiredRemovingCallback, $this);
            }
            $result = $this->removeSelf();
            $this->trigger(static::$eventExpiredRemoved, new ModelEvent(['data' => ['result' => $result]]));
            return true;
        }
        return false;
    }
1341052
public function destroyExpiredCache()
    {
        $cacheData = $this->getCache();

        if (true === is_array($cacheData)) {
            $counter = 0;
            foreach ($cacheData as $key => $entry) {
                if (true === $this->isExpired($entry['time'], $entry['expire'])) {
                    unset($cacheData[$key]);
                    $counter++;
                }
            }

            if ($counter > 0) {
                $cacheData = json_encode($cacheData);
                @file_put_contents($this->getDirectory(), $cacheData);
            }

            return $counter;
        }
    }
187302
protected function isCached()
    {
        $cacheTime = self::CACHE_TIME * 60;

        if (!is_file($this->pathCache)) {
            return false;
        }

        $cachedTime = filemtime($this->pathCache);
        $cacheAge = $this->time - $cachedTime;

        return $cacheAge < $cacheTime;
    }
443587
public function deleteOutdated(): bool
    {
        //TODO: check the need to call
        clearstatcache();
        
        $dh = @opendir($this->cacheDir);
        if (false === $dh) {
            return false;
        }
        
        while (false !== ($entry = readdir($dh))) {
            $filePath = $this->cacheDir . '/' . $entry;
            
            //exclude '.', '..', '.htaccess'
            if (!is_file($filePath) || 0 === strpos($entry, '.')) {
                continue;
            }
            
            try {
                $packet = $this->getPacketFromFile($filePath);
                if ($packet->outdated()) {
                    unlink($filePath);
                }
            } catch (BadPacketException $e) {
                unlink($filePath);
            }
        }
        
        closedir($dh);
        
        return true;
    }
798580
private function saveData(): bool
    {
        if ($cacheTime = $this->getMeta()->getCache()) {
            return Cache::set(
                $this->key,
                $this->getData(),
                $cacheTime,
                ['system', 'data']
            );
        }
        return false;
    }
10038
public function isExpired() : bool
    {
        $expiresAt = $this->getCache()->get($this->getKey())['expires_at'] ?? null;

        return empty($expiresAt) || Carbon::parse($expiresAt)->lt(Carbon::now());
    }
523370
public function expireAll()
    {
        if (!$this->enabled)
            return true;

        $this->Logger->debug('Expire all keys');

        $apcMethod = $this->apcFuncPrefix.'_clear_cache';
        $apcMethod();

        return $apcMethod('user');
    }
400109
public function isExpired()
    {
        return $this->hasPayLoad() && ($this->payLoad['created'] + $this->payLoad['expires_in']) < Carbon::now()
                                                                                                         ->format('U');
    }
657689
public function process()
    {
        $this->report->deleteExpired();
        $this->history->deleteExpired();

        // Delete files in temporary directory
        foreach (gplcart_file_scan_recursive(GC_DIR_PRIVATE_TEMP) as $file) {
            if (strpos(basename($file), '.') !== 0) { // Ignore hidden files
                gplcart_file_delete_recursive($file);
            }
        }

        $result = $this->report->checkFilesystem();

        if ($result !== true) {
            foreach ((array) $result as $message) {
                $this->logger->log('system_status', array('message' => $message), 'warning');
            }
        }

        return true;
    }
198962
public function getExpiredAfter()
    {
        if (!is_string($this->expiredAfterAttribute) || empty($this->expiredAfterAttribute)) {
            return false;
        }
        return (int)($this->{$this->expiredAfterAttribute});
    }
31324
public function clearExpired()
    {
        if ($this->options['cache']) {
            $keys = Ioc::cache($this->options['name'])->clearExpired();
        }
        
        return ErrorInfo::success($this->options['name'] . ' clear success: ' . $count . ' items');
    }
973978
public function expired(string $key): bool
    {
        try {
            return $this->storage->expired($key);
        } catch (BadPacketException $e) {
            return true;
        }
    }
243462
public long cleanup() {
		int garbageSize = 0;
		if (isCachingEnabled()) {
			System.out.println(new LogEntry(Level.VERBOSE, "Identifying expired objects"));
			ArrayList<K> garbage = getExpiredObjects();
			garbageSize = garbage.size();
			System.out.println(new LogEntry("cache cleanup: expired objects: " + garbageSize));
			for (K key : garbage) {
				clear(key);
			}
		}
		return garbageSize;
	}