Saves generated map to file

@param string $cacheFilePath     Path to cache file
@param array $map    Generated map
@return int
549221
private function cacheMap($cacheFilePath, $map)
    {
        if (!file_exists(dirname($cacheFilePath))) {
            mkdir(dirname($cacheFilePath), 0777, true);
        }
        return FileWriter::writeObject($cacheFilePath, $map, true);
    }
84439
protected function writeCacheFile(string $cacheEntryPathAndFilename, string $data)
    {
        for ($i = 0; $i < 3; $i++) {
            // This can be replaced by a simple file_put_contents($cacheEntryPathAndFilename, $data, LOCK_EX) once vfs
            // is fixed for file_put_contents with LOCK_EX, see https://github.com/mikey179/vfsStream/wiki/Known-Issues
            $result = false;
            try {
                $file = fopen($cacheEntryPathAndFilename, 'wb');
                if ($file === false) {
                    continue;
                }
                if (flock($file, LOCK_EX) !== false) {
                    $result = fwrite($file, $data);
                    flock($file, LOCK_UN);
                }
                fclose($file);
            } catch (\Exception $e) {
            }
            if ($result !== false) {
                clearstatcache(true, $cacheEntryPathAndFilename);
                return $result;
            }
            usleep(rand(10, 500));
        }

        return false;
    }
975952
function storeCacheFile( $filepath, $transformationData,$extraCode, $type, $charsetName )
    {
        $file = basename( $filepath );
        $dir = dirname( $filepath );
        $php = new eZPHPCreator( $dir, $file );

        $php->addComment( "Cached transformation data" );
        $php->addComment( "Type: $type" );
        $php->addComment( "Charset: $charsetName" );
        $php->addComment( "Cached transformation data" );

        $php->addCodePiece( '$data = ' . eZCharTransform::varExport( $transformationData ) . ";\n" );
        $php->addCodePiece( "\$text = strtr( \$text, \$data['table'] );\n" );

        if ( $extraCode )
        {
            $php->addCodePiece( $extraCode );
        }

        return $php->store( true );
    }
159206
private function saveIntoCache($key, MessageInterface $message)
    {
        if ($this->cache) {
            $item = $this->cache->getItem($key);

            $item->set([
                $message->getHeaders(),
                (string) $message->getBody(),
            ]);

            $this->cache->save($item);
        }
    }
694647
public function fileCacheSet($key, $value, $cache_time = 86400)
    {
        if ($this->isSingle()) {
            FilecacheKit::add($key, $value, $cache_time);
        }
    }
903658
public function isCached($cacheKey)
    {
        // TODO: Refactor for strict types!
        $path = $this->resolvePath($cacheKey, false);
        if (file_exists($path)) {
            return $path;
        } else {
            return false;
        }
    }
933655
public function compile(File $file, File $cacheFile) {
        $this->file = $file;
        $content = $this->compileString($file->read());
        return $cacheFile->write($this->compileHeaders().$content) !== false;
    }
1204084
public function saveMap($content)
    {
        $file = $this->options['sourceMapWriteTo'];
        $dir  = dirname($file);

        // directory does not exist
        if (! is_dir($dir)) {
            // FIXME: create the dir automatically?
            throw new CompilerException(sprintf('The directory "%s" does not exist. Cannot save the source map.', $dir));
        }

        // FIXME: proper saving, with dir write check!
        if (file_put_contents($file, $content) === false) {
            throw new CompilerException(sprintf('Cannot save the source map to "%s"', $file));
        }

        return $this->options['sourceMapURL'];
    }
1310381
public function cache($file, $content, $timestamp = null)
    {
        if (!$cachePath = $this->cachePath()) {
            throw new JitException('Error, any cache path has been defined.');
        }
        $path = $cachePath . DS . ltrim(preg_replace('~:~', '', $file), DS);

        if (!@file_exists(dirname($path))) {
            mkdir(dirname($path), 0755, true);
        }

        if (file_put_contents($path, $content) === false) {
            throw new JitException("Unable to create a cached file at `'{$file}'`.");
        }
        if ($timestamp) {
            touch($path, $timestamp);
        }
        return $path;
    }
69415
public static String generateCacheFileFullPath(String url, File cacheDir) {
		String fileName = md5(url);
		File cacheFile = new File(cacheDir, fileName);
		return cacheFile.getPath();
	}
766738
protected function cacheFile($path, $cachefsPath)
    {
        if (array_key_exists($path, $this->cachedFiles)) {
            return;
        }

        if (file_exists($path)) {
            $contents = file_get_contents($path);
            file_put_contents($cachefsPath, $contents);

            $this->cachedFiles[$path] = $cachefsPath;
        }
    }
922065
public function write(File $file)
    {
        $success = file_put_contents(
            $this->getRouteCachePath($file->getRoute()),
            $file->toString()
        );
        if ($success === false) {
            throw new CacheFileSystemException(
                "Unable to save Cache file to disk in file " . $this->getRouteCachePath($file->getRoute())
            );
        }
    }
497242
public function setCachePath($cachePath)
    {
        if (!is_dir($cachePath)) {
            throw new Exception\CachePathNotFoundException(sprintf('Cache Path, %s does not exists', $cachePath));
        }
        $this->cachePath = $cachePath;

        return $this;
    }
582138
public function cacheFile($cacheKey, $fileContents) {

        // Get directory and filename
        list($directory, $filename) = $this->getDirectoryAndFilenameFromKey($cacheKey);

        // Make the cache directory
        if (!file_exists($directory)) mkdir($directory, 0777, true);

        // Save the file
        file_put_contents($directory . "/" . $filename, $fileContents);

    }
1195147
public function write($key, $content, $timestamp = null)
    {
        if (!isset($this->cacheDirectory)) {
            return;
        }

        $this->loadCacheMetaData();
        $this->metaData[$key] = $timestamp;
        $this->dirty = true;

        if (!is_dir($this->cacheDirectory)) {
            mkdir($this->cacheDirectory, 0775, true);
        }
        file_put_contents($this->cacheDirectory . '/' . $key, serialize($content));
    }
12228
protected function write($map, $fileName)
    {
        $content = json_encode($map, JSON_PRETTY_PRINT);

        if (!file_exists($fileName)) {
            file_put_contents($fileName, $content);
            return;
        }

        $oldContent = file_get_contents($fileName);
        // prevent file lastModified time change
        if ($content !== $oldContent) {
            file_put_contents($fileName, $content);
        }
    }
1119755
private void persistCache(String projectName, String projectVersion, Map<String, String> cache) {
		File cacheFile = new File(getCacheDir(), projectName + "/" + projectVersion);
		ObjectOutputStream oos = null;
		try {
			oos = new ObjectOutputStream(new FileOutputStream(cacheFile));
			oos.writeObject(cache);
		}
		catch (IOException ioe) {
			LOGGER.warn("Unable to create the cache file {}/{}/{}", getCacheDir().getAbsoluteFile(), projectName, projectVersion);
		}
		finally { if (oos != null) { try { oos.close(); } catch (IOException ioe) {} } }
	}