Neos\Cache\Backend\SimpleFileBackend::readCacheFile PHP Method

readCacheFile() protected method

Reads the cache data from the given cache file, using locking.
protected readCacheFile ( string $cacheEntryPathAndFilename, integer | null $offset = null, integer | null $maxlen = null ) : boolean | string
$cacheEntryPathAndFilename string
$offset integer | null
$maxlen integer | null
return boolean | string The contents of the cache file or FALSE on error
    protected function readCacheFile($cacheEntryPathAndFilename, $offset = null, $maxlen = null)
    {
        for ($i = 0; $i < 3; $i++) {
            $data = false;
            try {
                $file = fopen($cacheEntryPathAndFilename, 'rb');
                if ($file === false) {
                    continue;
                }
                if (flock($file, LOCK_SH) !== false) {
                    if ($offset !== null) {
                        fseek($file, $offset);
                    }
                    $data = fread($file, $maxlen !== null ? $maxlen : filesize($cacheEntryPathAndFilename) - (int) $offset);
                    flock($file, LOCK_UN);
                }
                fclose($file);
            } catch (\Exception $e) {
            }
            if ($data !== false) {
                return $data;
            }
            usleep(rand(10, 500));
        }
        return $data;
    }