YamlCacheCollector.php

Same filename and directory in other branches
  1. 11.x core/lib/Drupal/Core/Utility/YamlCacheCollector.php

Namespace

Drupal\Core\Utility

File

core/lib/Drupal/Core/Utility/YamlCacheCollector.php

View source
<?php

declare (strict_types=1);
namespace Drupal\Core\Utility;

use Drupal\Component\Datetime\Time;
use Drupal\Component\Serialization\Yaml;
use Drupal\Core\Cache\MemoryCache\MemoryCache;
use Drupal\Core\Lock\NullLockBackend;

/**
 * Caches YAML parsing in a cache collector.
 */
class YamlCacheCollector extends FileParsingCacheCollectorBase {
  
  /**
   * Creates an instance of the class with a memory cache.
   *
   * This can be used where there is zero expectation of a cache hit rate or in
   * testing.
   */
  public static function createWithMemoryCache() : static {
    return new static('static_cache_key', new MemoryCache(new Time()), new NullLockBackend(), new Time());
  }
  
  /**
   * {@inheritdoc}
   */
  protected function parseFile($file) : array {
    return Yaml::decode($file) ?? [];
  }

}

Classes

Title Deprecated Summary
YamlCacheCollector Caches YAML parsing in a cache collector.

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