Example #1
0
 /**
  * {@inheritdoc}
  */
 public function getTimestamp($key)
 {
     if ($this->files->exists($key)) {
         return $this->files->time($key);
     }
     return 0;
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function gc($maxlifetime)
 {
     foreach ($this->files->getFiles($this->location) as $filename) {
         if ($this->files->time($filename) < time() - $maxlifetime) {
             $this->files->delete($filename);
         }
     }
 }
Example #3
0
 /**
  * Last update time.
  *
  * @param string $key
  * @return int
  */
 public function getTimestamp($key)
 {
     if (!$this->environment->cachable()) {
         //Always expired
         return 0;
     }
     if ($this->files->exists($key)) {
         return $this->files->time($key);
     }
     return 0;
 }
Example #4
0
 /**
  * {@inheritdoc}
  */
 public function report()
 {
     $this->debugger->logger()->error($this->getMessage());
     if (!$this->config['reporting']['enabled']) {
         //No need to record anything
         return;
     }
     //Snapshot filename
     $filename = \Spiral\interpolate($this->config['reporting']['filename'], ['date' => date($this->config['reporting']['dateFormat'], time()), 'exception' => $this->getName()]);
     //Writing to hard drive
     $this->files->write($this->config['reporting']['directory'] . '/' . $filename, $this->render(), FilesInterface::RUNTIME, true);
     $snapshots = $this->files->getFiles($this->config['reporting']['directory']);
     if (count($snapshots) > $this->config['reporting']['maxSnapshots']) {
         $oldestSnapshot = '';
         $oldestTimestamp = PHP_INT_MAX;
         foreach ($snapshots as $snapshot) {
             $snapshotTimestamp = $this->files->time($snapshot);
             if ($snapshotTimestamp < $oldestTimestamp) {
                 $oldestTimestamp = $snapshotTimestamp;
                 $oldestSnapshot = $snapshot;
             }
         }
         $this->files->delete($oldestSnapshot);
     }
 }
Example #5
0
 /**
  * {@inheritdoc}
  */
 public function isCompiled()
 {
     if (!$this->config['cache']['enabled']) {
         return false;
     }
     if (!$this->files->exists($viewFilename = $this->compiledFilename())) {
         return false;
     }
     return $this->files->time($viewFilename) >= $this->files->time($this->filename);
 }
Example #6
0
 /**
  * Clean old snapshots.
  *
  * @todo Possibly need better implementation.
  * @param array $snapshots
  */
 protected function performRotation(array $snapshots)
 {
     $oldest = '';
     $oldestTimestamp = PHP_INT_MAX;
     foreach ($snapshots as $snapshot) {
         $snapshotTimestamp = $this->files->time($snapshot);
         if ($snapshotTimestamp < $oldestTimestamp) {
             $oldestTimestamp = $snapshotTimestamp;
             $oldest = $snapshot;
         }
     }
     $this->files->delete($oldest);
 }
Example #7
0
 /**
  * Get unique file hash to improve resources caching.
  *
  * @todo add ability to disable this option
  * @param string $uri
  * @return string
  */
 protected function fileHash($uri)
 {
     return base_convert($this->files->time($this->directories->directory('public') . $uri), 10, 32);
 }
Example #8
0
 /**
  * {@inheritdoc}
  */
 public function isFresh($name, $time)
 {
     return $this->files->time($this->findView($name)) <= $time;
 }