Write the cache file

@param  string $filename  The cache file filename
@param  string $data      A serialized string of data
@param  string $directory The directory path
@param  int    $ttl       The time to live of this cache object
@return bool
336426
private function _write($filename, $data, $directory = null, $ttl = null)
    {
        $cache_path = $this->config->get('cache_path');

        // did they provide a subdirectory to namespace the cache?
        if ($directory) {
            $path = $cache_path.$directory.'/';
        } else {
            // they didn't provide a directory so we set the directory used for simple object caching
            $path = $cache_path.$this->config->get('object_dir');
        }

        if ( ! is_dir($path) and ! @mkdir($path, $this->config->get('dir_chmod'), true)) {
            throw new \QuickCacheException($path.' is not writable and cannot be created.');
        }

        // if we can't open perhaps it is being written by another, just return
        if ( ! $fh = @fopen($path.$filename.'.cache', 'wb')) return;

        // if no ttl is provided use the default
        if (is_null($ttl)) $ttl = $this->config->get('expiration');

        // using the current time and the ttl set the expiration date
        $expires = time() + (int) $ttl;

        flock($fh, LOCK_EX);
        fwrite($fh, $expires.$data);
        flock($fh, LOCK_UN);
        fclose($fh);

        return $data;
    }
1253554
public function encode($data, $ttl)
    {
        $expire = null;
        if ($ttl !== null) {
            $expire = time() + $ttl;
        }
        return serialize(array($data, $expire));
    }
389894
protected function storeRawData( $filename, $data )
    {
        if ( file_put_contents( $filename, $data ) !== strlen( $data ) )
        {
            throw new ezcBaseFileIoException(
                $filename,
                ezcBaseFileException::WRITE,
                'Could not write data to cache file.'
            );
        }
    }
485289
protected function writeCache( $fileName )
	{
		$file		= new FS_File_Writer( $fileName, 0777 );
		$content	= serialize( $this->getConfigValues() );
		$file->writeString( $content );
		touch( $fileName, filemtime( $this->pathConfig.$this->fileName ) );
	}
787256
public function save( $id, $data, $ttl = 0 ) {
		$this->cache->save( $id, $data, $ttl );
	}
734318
function write($filename,$content){
		if(!Config::read('App.Base.enable_cache')){
			return;
		}
		$expire = time() + ($this->getConfig('cache_expiration') * 60);

		$filename = md5($filename);
		$filepath = $this->getConfig('cache_path').$filename.'.tmp';

		if ( ! $fp = @fopen($filepath, 'w')){
			Loader::getClass('Sky.core.Log')->write(400,'Unable to write cache file: '.$filepath);
			Exceptions::showError('error', "Unable to write cache file: ".$filepath);
			
		}
		if (flock($fp, LOCK_EX))
		{
			fwrite($fp, $expire.'T_SKY-->'.$content);
			flock($fp, LOCK_UN);
		}
		else{
			Loader::getClass('Sky.core.Log')->write(300,'Unable to secure a file lock for file at: '.$filepath);
			return;
		}
		fclose($fp);
		@chmod($filepath,0755);
		
	}
322057
public function stream_write($data)
    {
        if (!$this->currentlyOpenedFile->isOpenedForWriting()) {
            return false;
        }
        //file access time changes so stat cache needs to be cleared
        $written = $this->currentlyOpenedFile->write($data);
        clearstatcache();

        return $written;
    }
1360291
function write($id,$data) {
		$fw=Base::instance();
		$jar=$fw->JAR;
		$this->_cache->set($id.'.@',
			[
				'data'=>$data,
				'ip'=>$this->_ip,
				'agent'=>$this->_agent,
				'stamp'=>time()
			],
			$jar['expire']
		);
		return TRUE;
	}
1370843
public function writeFile(string $filename, string $data, int $mode = null) : void
    {
        if ($mode === null) {
            $mode = 0600;
        }
        /** @psalm-suppress UndefinedClass */
        System::writeFile($filename, $data, $mode);
    }
876085
private function _delete($filename, $directory = null)
    {
        $cache_path = $this->config->get('cache_path');

        if (is_null($directory)) {
            $path = $cache_path.$this->config->get('object_dir').$filename.'.cache';
        } else {
            $path = $cache_path.$directory.$filename.'.cache';
        }

        // nope. not here.
        if ( ! file_exists($path)) return true;
        return (bool) unlink($path);
    }
122421
public function writeToFile($filename, $data, $header = '')
    {
        $ini = $this->writeToString($data, $header);
        if (!file_put_contents($filename, $ini))
            throw new IniWritingException(sprintf('Impossible to write to file %s', $filename));
    }
590066
static public function save($key, $data, $force = false, $ttl = 1440) {
        return self::getDriver()->save($key, $data, $force, $ttl);
    }
247703
public function set($key, $data, $ttl)
    {
        $this->ttl = $ttl;

        $filename = $this->cacheDir . DIRECTORY_SEPARATOR . $this->processKey($key);

        return $this->safelyWriteData($filename, 'w', serialize($data));
    }
802400
def write_to_cache(self, data, filename=''):
        '''  '''
        if not filename:
            filename = self.cache_path_cache
        json_data = json.dumps(data)
        with open(filename, 'w') as cache:
            cache.write(json_data)
        return True
846516
public function dump($data, $ttl=null) {

        return $this->getCache()
            ->setNamespace(self::CACHE_NAMESPACE)
            ->set(self::CACHE_NAME, $data, $ttl === null ? self::DEFAULTTTL : intval($ttl));

    }
1277261
protected function saveToCache($data)
    {
        $fh = fopen($this->filePath, 'w');
        if (flock($fh, LOCK_EX)) {
            fwrite($fh, $data);
            flock($fh, LOCK_UN);
        }
        fclose($fh);
        $this->log->debug("Cache file {$this->filePath} saved");
    }
1036433
public function set($key, $data, $ttl = null)
    {
        if ($ttl) {
            $now = new \DateTime('now', new \DateTimeZone('UTC'));
            $expire = (int) $now->format('U') + $ttl;
        } else {
            $expire = 0;
        }

        $entry = array(
            'expire' => $expire,
            'value' => $data
        );

        $this->storage[$key] = $entry;

        return true;
    }