Use the file modify time as cache key to store an item from a callback

@param string $file The path of file
@param callable $fn The callback to get and parse file content
@return mixed
549526
public function getFileContent($file, $fn)
    {
        $key = $file . filemtime($file);
        return $this->get($key, function($wei, $cache) use ($file, $fn) {
            return $fn($file, $wei, $cache);
        });
    }
959615
public function make($file) {
        if (!$file instanceof File && is_file($file)) {
            $file = new File($file);
        }
        if (!$file instanceof File) {
            $file = $this->directory->childFile($this->fileSuffix($file));
        }
        if (!$file->exist()) {
            throw new FileException($file);
        }
        if (!$this->engine instanceof EngineObject) {
            return new View($this, $file);
        }
        /** IF HAS ENGINE*/
        $cacheFile = $this->cache->getCacheFile($file->getFullName());
        if (!$cacheFile->exist() || $cacheFile->modifyTime() < $file->modifyTime()) {
            $this->engine->compile($file, $cacheFile);
        }
        return new View($this, $file, $cacheFile);
    }
717509
public function cached($file)
    {
        if (!$cachePath = $this->cachePath()) {
            return false;
        }
        $path = $cachePath . DS . ltrim(preg_replace('~:~', '', $file), DS);

        if (!@file_exists($path)) {
            return false;
        }

        $timestamp = filemtime($path);
        if ($timestamp > filemtime($file) && $timestamp > $this->_watchedTimestamp) {
            return $path;
        }
        return false;
    }
1329562
public function read($file)
    {
        $fp = fopen($file, 'r+');

        $contents = '';

        while ($part = fread($fp, 1024)) {
            $contents .= $part;
        }

        if (null !== $fp) {
            fclose($fp);
        }

        return $contents;
    }
939299
protected function read($file)
    {
        $data = null;
        $key  = $file;
        $file = $this->getFileName($file);

        if ( file_exists($file))
        {
            // if cache file not expire
            if (filemtime($file) >= time())
            {
                echo "read cache<br/>";
                $data = file_get_contents($file);
                $data = ($this->base64Encode) ? base64_decode($data) : $data;
                $data = unserialize($data);
                static::$keys[$key] = true;
            }
            else
            {
                unset(static::$keys[$key]);
                unlink($file);
            }
        }

        return $data;
    }
730779
protected function _fileGetContents($file)
    {
        if (!is_file($file)) {
            return false;
        }

        if ($this->_options['mode'] == 1) {
            $f = @fopen($file, 'r');
            @$data = fread($f, filesize($file));
            @fclose($f);
            return unserialize($data);
        } else {
            return include $file;
        }
    }
894921
protected function getCache($key, $refresh, callable $fn)
    {
        if ($refresh || $this->isRefresh()) {
            $this->configCache->remove($key);
        }

        return $this->configCache->get($key, function () use ($fn) {
            return $fn();
        });
    }
440913
private function getFileKey(\SplFileInfo $file)
    {
        $key = null;

        if ($h = @fopen($file, 'r')) {
            rawurldecode(rtrim(fgets($h)));
            $value = stream_get_contents($h);
            fclose($h);
            $key = substr($value, 0, strpos($value, "\n"));
        }

        return $key;
    }
160145
public function getFilemtimeCurrent($file)
    {
        if(is_readable($file) === false)
            return false;

        $time = filemtime($file);

        return $time ? $time : false;
    }
29980
public function setFile($file)
    {
        if (!is_file($file)) {
            throw new \InvalidArgumentException('File not found: '.$file, ErrorCodes::FILE_NOT_FOUND);
        }
        if (!is_readable($file)) {
            throw new \InvalidArgumentException('File is not readable: '.$file, ErrorCodes::FILE_NOT_READABLE);
        }
        $this->file = $file;
        return $this;
    }
800296
public static function get($file = false) {

        if ($file && self::isFile($file)) {

            return file_get_contents($file);
        }

        return false;
    }
180461
public function getStreamedFileFunction($file)
    {
        return function() use ($file) {
            set_time_limit(0);
            $handle = fopen($file, 'rb');
            if ($handle !== false) {
                $chunkSize = 1024 * 1024;
                while (!feof($handle)) {
                    $buffer = fread($handle, $chunkSize);
                    echo $buffer;
                    flush();
                }
                fclose($handle);
            }
        };
    }
227246
function file_get_contents($file)
		{
			$fd = fopen($file, 'rb');
			$content = fread($fd, filesize($file));
			fclose($fd);
			$this->file_loaded_size+= strlen($content);
			return $content;				
		}
941791
static function storeCachedFile( $file, $content )
    {
        $dir = dirname( $file );
        if ( !is_dir( $dir ) )
        {
            eZDir::mkdir( $dir, false, true );
        }

        $oldumask = umask( 0 );

        $tmpFileName = $file . '.' . md5( $file. uniqid( "ezp". getmypid(), true ) );

        // Remove files, this might be necessary for Windows
        @unlink( $tmpFileName );

        // Write the new cache file with the data attached
        $fp = fopen( $tmpFileName, 'w' );
        if ( $fp )
        {
            $comment = ( eZINI::instance( 'staticcache.ini' )->variable( 'CacheSettings', 'AppendGeneratedTime' ) === 'true' ) ? "<!-- Generated: " . date( 'Y-m-d H:i:s' ). " -->\n\n" : null;

            fwrite( $fp, $content . $comment );
            fclose( $fp );
            eZFile::rename( $tmpFileName, $file, false, eZFile::CLEAN_ON_FAILURE | eZFile::APPEND_DEBUG_ON_FAILURE );

            $perm = eZINI::instance()->variable( 'FileSettings', 'StorageFilePermissions' );
            chmod( $file, octdec( $perm ) );
        }

        umask( $oldumask );
    }
459702
protected function loadFile($file)
    {
        if (!stream_is_local($file)) {
            throw new \InvalidArgumentException(sprintf('Procedure file is not a local file: "%s"', $file));
        }

        if (!file_exists($file)) {
            throw new NotExistsException(sprintf('Procedure file does not exist: "%s"', $file));
        }

        return file_get_contents($file);
    }
1075284
protected function locateFile($file)
    {
        $this->locateFile && $file = call_user_func($this->locateFile, $file);

        return $file;
    }
607335
public static function parseFile($file)
    {
        if (!file_exists($file) || !is_readable($file)) {
            $message = "crontab config file is not exists or not readable";
            throw new \RuntimeException($message);
        }

        $tasks = array();
        $lines = file($file);
        foreach ($lines as $line) {
            $job = new JobParse($line);
            $tasks[] = $job->getTask();
        }

        return $tasks;
    }