protected function writeFile(EntityMetadata $metadata, $contents)
    {
        $file = $this->getCacheFile($metadata->type);
        $tmpFile = tempnam($this->dir, 'metadata-cache');
        file_put_contents($tmpFile, $contents);
        chmod($tmpFile, 0666 & ~umask());
        $this->renameFile($tmpFile, $file);
    }