/** * Write data for key into cache * * @param string $key Identifier for the data * @param mixed $data Data to be cached * @param integer $duration How long to cache the data, in seconds * @return boolean True if the data was successfully cached, false on failure */ public function write($key, $data, $duration) { if ($data === '' || !$this->_init) { return false; } if ($this->_setKey($key, true) === false) { return false; } $lineBreak = "\n"; if ($this->settings['isWindows']) { $lineBreak = "\r\n"; } if (!empty($this->settings['serialize'])) { if ($this->settings['isWindows']) { $data = str_replace('\\', '\\\\\\\\', serialize($data)); } else { $data = serialize($data); } } $expires = time() + $duration; $contents = $expires . $lineBreak . $data . $lineBreak; if ($this->settings['lock']) { $this->_File->flock(LOCK_EX); } $this->_File->rewind(); $success = $this->_File->ftruncate(0) && $this->_File->fwrite($contents) && $this->_File->fflush(); if ($this->settings['lock']) { $this->_File->flock(LOCK_UN); } return $success; }