/** * @param string $file * @param string $data * @param bool $secureFileManipulation * @return bool * @throws phpFastCacheIOException */ protected function writefile($file, $data, $secureFileManipulation = false) { /** * @eventName CacheWriteFileOnDisk * @param ExtendedCacheItemPoolInterface $this * @param string $file * @param bool $secureFileManipulation * */ $this->eventManager->dispatch('CacheWriteFileOnDisk', $this, $file, $secureFileManipulation); if ($secureFileManipulation) { $tmpFilename = Directory::getAbsolutePath(dirname($file) . '/tmp_' . md5(str_shuffle(uniqid($this->getDriverName(), false)) . str_shuffle(uniqid($this->getDriverName(), false)))); $f = fopen($tmpFilename, 'w+'); flock($f, LOCK_EX); $octetWritten = fwrite($f, $data); flock($f, LOCK_UN); fclose($f); if (!rename($tmpFilename, $file)) { throw new phpFastCacheIOException(sprintf('Failed to rename %s to %s', $tmpFilename, $file)); } } else { $f = fopen($file, 'w+'); $octetWritten = fwrite($f, $data); fclose($f); } return $octetWritten !== false; }
/** * @return driverStatistic * @throws \phpFastCache\Exceptions\phpFastCacheIOException */ public function getStats() { $stat = new driverStatistic(); $path = $this->getFilePath(false); if (!is_dir($path)) { throw new phpFastCacheIOException("Can't read PATH:" . $path); } $stat->setData(implode(', ', array_keys($this->itemInstances)))->setRawData(['tmp' => $this->tmp])->setSize(Directory::dirSize($path))->setInfo('Number of files used to build the cache: ' . Directory::getFileCount($path)); return $stat; }
/** * @return driverStatistic */ public function getStats() { return (new driverStatistic())->setData(implode(', ', array_keys($this->itemInstances)))->setInfo('Number of files used to build the cache: ' . Directory::getFileCount($this->getLeveldbFile()))->setSize(Directory::dirSize($this->getLeveldbFile())); }