Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. FilesystemCache.php

function FilesystemCache::write

Overrides CacheInterface::write

1 method overrides FilesystemCache::write()
ReadOnlyFilesystemCache::write in vendor/twig/twig/src/Cache/ReadOnlyFilesystemCache.php
Writes the compiled template to cache.

File

vendor/twig/twig/src/Cache/FilesystemCache.php, line 46

Class

FilesystemCache
Implements a cache on the filesystem.

Namespace

Twig\Cache

Code

public function write(string $key, string $content) : void {
    $dir = \dirname($key);
    if (!is_dir($dir)) {
        if (false === @mkdir($dir, 0777, true)) {
            clearstatcache(true, $dir);
            if (!is_dir($dir)) {
                throw new \RuntimeException(\sprintf('Unable to create the cache directory (%s).', $dir));
            }
        }
    }
    elseif (!is_writable($dir)) {
        throw new \RuntimeException(\sprintf('Unable to write in the cache directory (%s).', $dir));
    }
    $tmpFile = tempnam($dir, basename($key));
    if (false !== @file_put_contents($tmpFile, $content) && @rename($tmpFile, $key)) {
        @chmod($key, 0666 & ~umask());
        if (self::FORCE_BYTECODE_INVALIDATION == ($this->options & self::FORCE_BYTECODE_INVALIDATION)) {
            // Compile cached file into bytecode cache
            if (\function_exists('opcache_invalidate') && filter_var(\ini_get('opcache.enable'), \FILTER_VALIDATE_BOOLEAN)) {
                @opcache_invalidate($key, true);
            }
            elseif (\function_exists('apc_compile_file')) {
                apc_compile_file($key);
            }
        }
        return;
    }
    throw new \RuntimeException(\sprintf('Failed to write cache file "%s".', $key));
}
RSS feed
Powered by Drupal