Example #1
0
 /**
  * Read a key from the cache
  *
  * @param string $key Identifier for the data
  * @return mixed The cached data, or false if the data doesn't exist, has expired, or if there was an error fetching it
  */
 public function read($key)
 {
     if (!$this->_init || $this->_setKey($key) === false) {
         return false;
     }
     if ($this->settings['lock']) {
         $this->_File->flock(LOCK_SH);
     }
     $this->_File->rewind();
     $time = time();
     $cachetime = intval($this->_File->current());
     if ($cachetime !== false && ($cachetime < $time || $time + $this->settings['duration'] < $cachetime)) {
         if ($this->settings['lock']) {
             $this->_File->flock(LOCK_UN);
         }
         return false;
     }
     $data = '';
     $this->_File->next();
     while ($this->_File->valid()) {
         $data .= $this->_File->current();
         $this->_File->next();
     }
     if ($this->settings['lock']) {
         $this->_File->flock(LOCK_UN);
     }
     $data = trim($data);
     if ($data !== '' && !empty($this->settings['serialize'])) {
         if ($this->settings['isWindows']) {
             $data = str_replace('\\\\\\\\', '\\', $data);
         }
         $data = unserialize((string) $data);
     }
     return $data;
 }