Cache_Lite::_write PHP Method

_write() public method

Write the given data in the cache file
public _write ( string $data ) : boolean
$data string data to put in cache
return boolean true if ok (a PEAR_Error object else)
    function _write($data)
    {
        $oldmask = umask(0);
        if ($this->_hashedDirectoryLevel > 0) {
            $hash = md5($this->_fileName);
            $root = $this->_cacheDir;
            for ($i = 0; $i < $this->_hashedDirectoryLevel; $i++) {
                $root = $root . 'cache_' . substr($hash, 0, $i + 1) . '/';
                if (!@is_dir($root)) {
                    @mkdir($root, $this->_hashedDirectoryUmask);
                }
            }
        }
        $fp = @fopen($this->_file, "wb");
        if ($fp) {
            if ($this->_fileLocking) {
                @flock($fp, LOCK_EX);
            }
            if ($this->_readControl) {
                @fwrite($fp, $this->_hash($data, $this->_readControlType), 32);
            }
            $len = strlen($data);
            @fwrite($fp, $data, $len);
            if ($this->_fileLocking) {
                @flock($fp, LOCK_UN);
            }
            @fclose($fp);
            umask($oldmask);
            return true;
        }
        umask($oldmask);
        return $this->raiseError('Cache_Lite : Unable to write cache file : ' . $this->_file, -1);
    }