function FileCache::set

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Component/FileCache/FileCache.php \Drupal\Component\FileCache\FileCache::set()
  2. 8.9.x core/lib/Drupal/Component/FileCache/FileCache.php \Drupal\Component\FileCache\FileCache::set()
  3. 11.x core/lib/Drupal/Component/FileCache/FileCache.php \Drupal\Component\FileCache\FileCache::set()

Stores data based on a filename.

Parameters

string $filepath: Path of the file that the cached data is based on.

mixed $data: The data that should be cached.

Overrides FileCacheInterface::set

File

core/lib/Drupal/Component/FileCache/FileCache.php, line 123

Class

FileCache
Allows to cache data based on file modification dates.

Namespace

Drupal\Component\FileCache

Code

public function set($filepath, $data) {
  $realpath = realpath($filepath);
  $cached = [
    'mtime' => filemtime($filepath),
    'filepath' => $filepath,
    'data' => $data,
  ];
  $cid = $this->prefix . ':' . $this->collection . ':' . $realpath;
  static::$cached[$cid] = $cached;
  if ($this->cache) {
    $this->cache
      ->store($cid, $cached);
  }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.