You are here

class GroupRelationManager in Group 2.0.x

Manages GroupRelation plugin implementations.

Hierarchy

Expanded class hierarchy of GroupRelationManager

See also

hook_group_content_info_alter()

\Drupal\group\Annotation\GroupRelation

\Drupal\group\Plugin\Group\Relation\GroupRelationInterface

\Drupal\group\Plugin\Group\Relation\GroupRelationBase

Plugin API

1 file declares its use of GroupRelationManager
GroupRelationManagerTest.php in tests/src/Unit/GroupRelationManagerTest.php
1 string reference to 'GroupRelationManager'
group.services.yml in ./group.services.yml
group.services.yml
1 service uses GroupRelationManager
plugin.manager.group_relation in ./group.services.yml
Drupal\group\Plugin\Group\Relation\GroupRelationManager

File

src/Plugin/Group/Relation/GroupRelationManager.php, line 24

Namespace

Drupal\group\Plugin\Group\Relation
View source
class GroupRelationManager extends DefaultPluginManager implements GroupRelationManagerInterface, ContainerAwareInterface {
  use ContainerAwareTrait;

  /**
   * Contains instantiated handlers keyed by handler type and plugin ID.
   *
   * @var array
   */
  protected $handlers = [];

  /**
   * The entity type manager.
   *
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
   */
  protected $entityTypeManager;

  /**
   * The group type storage handler.
   *
   * @var \Drupal\Core\Config\Entity\ConfigEntityStorageInterface
   */
  protected $groupTypeStorage;

  /**
   * A group content type storage handler.
   *
   * @var \Drupal\group\Entity\Storage\GroupContentTypeStorageInterface
   */
  protected $groupContentTypeStorage;

  /**
   * A collection of vanilla instances of all group relation plugins.
   *
   * @var \Drupal\group\Plugin\Group\Relation\GroupRelationCollection
   */
  protected $allPlugins;

  /**
   * An list each group type's installed plugins as plugin collections.
   *
   * @var \Drupal\group\Plugin\Group\Relation\GroupRelationCollection[]
   */
  protected $groupTypeInstalled = [];

  /**
   * An static cache of group content type IDs per plugin ID.
   *
   * @var array[]
   */
  protected $pluginGroupContentTypeMap;

  /**
   * The cache key for the group content type IDs per plugin ID map.
   *
   * @var string
   */
  protected $pluginGroupContentTypeMapCacheKey;

  /**
   * An static cache of plugin IDs per group type ID.
   *
   * @var array[]
   */
  protected $groupTypePluginMap;

  /**
   * The cache key for the plugin IDs per group type ID map.
   *
   * @var string
   */
  protected $groupTypePluginMapCacheKey;

  /**
   * Constructs a GroupRelationManager object.
   *
   * @param \Traversable $namespaces
   *   An object that implements \Traversable which contains the root paths
   *   keyed by the corresponding namespace to look for plugin implementations.
   * @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend
   *   Cache backend instance to use.
   * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
   *   The module handler to invoke the alter hook with.
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   The entity type manager.
   */
  public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler, EntityTypeManagerInterface $entity_type_manager) {
    parent::__construct('Plugin/Group/Relation', $namespaces, $module_handler, 'Drupal\\group\\Plugin\\Group\\Relation\\GroupRelationInterface', 'Drupal\\group\\Annotation\\GroupRelation');
    $this
      ->alterInfo('group_relation_info');
    $this
      ->setCacheBackend($cache_backend, 'group_relations');
    $this->entityTypeManager = $entity_type_manager;
    $this->pluginGroupContentTypeMapCacheKey = $this->cacheKey . '_GCT_map';
    $this->groupTypePluginMapCacheKey = $this->cacheKey . '_GT_map';
  }

  /**
   * {@inheritdoc}
   */
  public function getHandler($plugin_id, $handler_type) {
    if (!isset($this->handlers[$handler_type][$plugin_id])) {
      $this->handlers[$handler_type][$plugin_id] = $this
        ->createHandlerInstance($plugin_id, $handler_type);
    }
    return $this->handlers[$handler_type][$plugin_id];
  }

  /**
   * {@inheritdoc}
   */
  public function createHandlerInstance($plugin_id, $handler_type) {
    $definition = $this
      ->getDefinition($plugin_id);
    $service_name = "group.relation_handler.{$handler_type}.{$definition['id']}";
    if (!$this->container
      ->has($service_name)) {
      throw new InvalidPluginDefinitionException($plugin_id, sprintf('The "%s" plugin did not specify a %s handler service (%s).', $plugin_id, $handler_type, $service_name));
    }
    $handler = $this->container
      ->get($service_name);
    if (!is_subclass_of($handler, 'Drupal\\group\\Plugin\\Group\\RelationHandler\\RelationHandlerInterface')) {
      throw new InvalidPluginDefinitionException($plugin_id, 'Trying to instantiate a handler that does not implement \\Drupal\\group\\Plugin\\Group\\RelationHandler\\RelationHandlerInterface.');
    }
    $handler
      ->init($plugin_id, $definition);
    return $handler;
  }

  /**
   * {@inheritdoc}
   */
  public function getAccessControlHandler($plugin_id) {
    return $this
      ->getHandler($plugin_id, 'access_control');
  }

  /**
   * {@inheritdoc}
   */
  public function getPermissionProvider($plugin_id) {
    return $this
      ->getHandler($plugin_id, 'permission_provider');
  }

  /**
   * {@inheritdoc}
   */
  public function getPostInstallHandler($plugin_id) {
    return $this
      ->getHandler($plugin_id, 'post_install');
  }

  /**
   * Returns the group type storage handler.
   *
   * @return \Drupal\Core\Config\Entity\ConfigEntityStorageInterface
   *   The group type storage handler.
   */
  protected function getGroupTypeStorage() {
    if (!isset($this->groupTypeStorage)) {
      $this->groupTypeStorage = $this->entityTypeManager
        ->getStorage('group_type');
    }
    return $this->groupTypeStorage;
  }

  /**
   * Returns the group content type storage handler.
   *
   * @return \Drupal\group\Entity\Storage\GroupContentTypeStorageInterface
   *   The group content type storage handler.
   */
  protected function getGroupContentTypeStorage() {
    if (!isset($this->groupContentTypeStorage)) {
      $this->groupContentTypeStorage = $this->entityTypeManager
        ->getStorage('group_content_type');
    }
    return $this->groupContentTypeStorage;
  }

  /**
   * {@inheritdoc}
   */
  public function getAll() {
    if (!isset($this->allPlugins)) {
      $collection = new GroupRelationCollection($this, []);

      // Add every known plugin to the collection with a vanilla configuration.
      foreach ($this
        ->getDefinitions() as $plugin_id => $plugin_info) {
        $collection
          ->setInstanceConfiguration($plugin_id, [
          'id' => $plugin_id,
        ]);
      }

      // Sort and set the plugin collection.
      $this->allPlugins = $collection
        ->sort();
    }
    return $this->allPlugins;
  }

  /**
   * {@inheritdoc}
   */
  public function getInstalled(GroupTypeInterface $group_type = NULL) {
    return !isset($group_type) ? $this
      ->getVanillaInstalled() : $this
      ->getGroupTypeInstalled($group_type);
  }

  /**
   * Retrieves a vanilla instance of every installed plugin.
   *
   * @return \Drupal\group\Plugin\Group\Relation\GroupRelationCollection
   *   A plugin collection with a vanilla instance of every installed plugin.
   */
  protected function getVanillaInstalled() {

    // Retrieve a vanilla instance of all known group relation plugins.
    $plugins = clone $this
      ->getAll();

    // Retrieve all installed group relation plugin IDs.
    $installed = $this
      ->getInstalledIds();

    // Remove uninstalled plugins from the collection.

    /** @var \Drupal\group\Plugin\Group\Relation\GroupRelationCollection $plugins */
    foreach ($plugins as $plugin_id => $plugin) {
      if (!in_array($plugin_id, $installed)) {
        $plugins
          ->removeInstanceId($plugin_id);
      }
    }
    return $plugins;
  }

  /**
   * Retrieves fully instantiated plugins for a group type.
   *
   * @param \Drupal\group\Entity\GroupTypeInterface $group_type
   *   The group type to instantiate the installed plugins for.
   *
   * @return \Drupal\group\Plugin\Group\Relation\GroupRelationCollection
   *   A plugin collection with fully instantiated plugins for the group type.
   */
  protected function getGroupTypeInstalled(GroupTypeInterface $group_type) {
    if (!isset($this->groupTypeInstalled[$group_type
      ->id()])) {
      $configurations = [];
      $group_content_types = $this
        ->getGroupContentTypeStorage()
        ->loadByGroupType($group_type);

      // Get the plugin config from every group content type for the group type.
      foreach ($group_content_types as $group_content_type) {
        $plugin_id = $group_content_type
          ->getRelationPluginId();

        // Grab the plugin config from every group content type and amend it
        // with the group type ID so the plugin knows what group type to use. We
        // also specify the 'id' key because DefaultLazyPluginCollection throws
        // an exception if it is not present.
        $configuration = $group_content_type
          ->get('plugin_config');
        $configuration['group_type_id'] = $group_type
          ->id();
        $configuration['id'] = $plugin_id;
        $configurations[$plugin_id] = $configuration;
      }
      $plugins = new GroupRelationCollection($this, $configurations);
      $plugins
        ->sort();
      $this->groupTypeInstalled[$group_type
        ->id()] = $plugins;
    }
    return $this->groupTypeInstalled[$group_type
      ->id()];
  }

  /**
   * {@inheritdoc}
   */
  public function getInstalledIds(GroupTypeInterface $group_type = NULL) {

    // If no group type was provided, we can find all installed plugin IDs by
    // grabbing the keys from the group content type IDs per plugin ID map.
    if (!isset($group_type)) {
      return array_keys($this
        ->getPluginGroupContentTypeMap());
    }

    // Otherwise, we can find the entry in the plugin IDs per group type ID map.
    $map = $this
      ->getGroupTypePluginMap();
    return isset($map[$group_type
      ->id()]) ? $map[$group_type
      ->id()] : [];
  }

  /**
   * {@inheritdoc}
   */
  public function getPluginIdsByEntityTypeAccess($entity_type_id) {
    $plugin_ids = [];
    foreach ($this
      ->getDefinitions() as $plugin_id => $plugin_info) {
      if (!empty($plugin_info['entity_access']) && $plugin_info['entity_type_id'] == $entity_type_id) {
        $plugin_ids[] = $plugin_id;
      }
    }
    return $plugin_ids;
  }

  /**
   * {@inheritdoc}
   */
  public function installEnforced(GroupTypeInterface $group_type = NULL) {
    $enforced = [];

    // Gather the ID of all plugins that are marked as enforced.
    foreach ($this
      ->getDefinitions() as $plugin_id => $plugin_info) {
      if ($plugin_info['enforced']) {
        $enforced[] = $plugin_id;
      }
    }

    // If no group type was specified, we check all of them.

    /** @var \Drupal\group\Entity\GroupTypeInterface[] $group_types */
    $group_types = empty($group_type) ? $this
      ->getGroupTypeStorage()
      ->loadMultiple() : [
      $group_type,
    ];

    // Search through all of the enforced plugins and install new ones.
    foreach ($group_types as $group_type) {
      $installed = $this
        ->getInstalledIds($group_type);
      foreach ($enforced as $plugin_id) {
        if (!in_array($plugin_id, $installed)) {
          $this
            ->getGroupContentTypeStorage()
            ->createFromPlugin($group_type, $plugin_id)
            ->save();
        }
      }
    }
  }

  /**
   * {@inheritdoc}
   */
  public function getGroupContentTypeIds($plugin_id) {
    $map = $this
      ->getPluginGroupContentTypeMap();
    return isset($map[$plugin_id]) ? $map[$plugin_id] : [];
  }

  /**
   * {@inheritdoc}
   */
  public function getPluginGroupContentTypeMap() {
    $map = $this
      ->getCachedPluginGroupContentTypeMap();
    if (!isset($map)) {
      $map = [];

      /** @var \Drupal\group\Entity\GroupContentTypeInterface[] $group_content_types */
      $group_content_types = $this
        ->getGroupContentTypeStorage()
        ->loadMultiple();
      foreach ($group_content_types as $group_content_type) {
        $map[$group_content_type
          ->getRelationPluginId()][] = $group_content_type
          ->id();
      }
      $this
        ->setCachedPluginGroupContentTypeMap($map);
    }
    return $map;
  }

  /**
   * Returns the cached group content type ID map.
   *
   * @return array|null
   *   On success this will return the group content ID map (array). On failure
   *   this should return NULL, indicating to other methods that this has not
   *   yet been defined. Success with no values should return as an empty array.
   */
  protected function getCachedPluginGroupContentTypeMap() {
    if (!isset($this->pluginGroupContentTypeMap) && ($cache = $this
      ->cacheGet($this->pluginGroupContentTypeMapCacheKey))) {
      $this->pluginGroupContentTypeMap = $cache->data;
    }
    return $this->pluginGroupContentTypeMap;
  }

  /**
   * Sets a cache of the group content type ID map.
   *
   * @param array $map
   *   The group content type ID map to store in cache.
   */
  protected function setCachedPluginGroupContentTypeMap(array $map) {
    $this
      ->cacheSet($this->pluginGroupContentTypeMapCacheKey, $map, Cache::PERMANENT);
    $this->pluginGroupContentTypeMap = $map;
  }

  /**
   * {@inheritdoc}
   */
  public function getGroupTypePluginMap() {
    $map = $this
      ->getCachedGroupTypePluginMap();
    if (!isset($map)) {
      $map = [];

      /** @var \Drupal\group\Entity\GroupContentTypeInterface[] $group_content_types */
      $group_content_types = $this
        ->getGroupContentTypeStorage()
        ->loadMultiple();
      foreach ($group_content_types as $group_content_type) {
        $map[$group_content_type
          ->getGroupTypeId()][] = $group_content_type
          ->getRelationPluginId();
      }
      $this
        ->setCachedGroupTypePluginMap($map);
    }
    return $map;
  }

  /**
   * Returns the cached group type plugin map.
   *
   * @return array|null
   *   On success this will return the group type plugin map (array). On failure
   *   this should return NULL, indicating to other methods that this has not
   *   yet been defined. Success with no values should return as an empty array.
   */
  protected function getCachedGroupTypePluginMap() {
    if (!isset($this->groupTypePluginMap) && ($cache = $this
      ->cacheGet($this->groupTypePluginMapCacheKey))) {
      $this->groupTypePluginMap = $cache->data;
    }
    return $this->groupTypePluginMap;
  }

  /**
   * Sets a cache of the group type plugin map.
   *
   * @param array $map
   *   The group type plugin map to store in cache.
   */
  protected function setCachedGroupTypePluginMap(array $map) {
    $this
      ->cacheSet($this->groupTypePluginMapCacheKey, $map, Cache::PERMANENT);
    $this->groupTypePluginMap = $map;
  }

  /**
   * {@inheritdoc}
   */
  public function clearCachedGroupTypeCollections(GroupTypeInterface $group_type = NULL) {
    if (!isset($group_type)) {
      $this->groupTypeInstalled = [];
    }
    else {
      $this->groupTypeInstalled[$group_type
        ->id()] = NULL;
    }
  }

  /**
   * {@inheritdoc}
   */
  public function clearCachedPluginMaps() {
    if ($this->cacheBackend) {
      $this->cacheBackend
        ->delete($this->pluginGroupContentTypeMapCacheKey);
      $this->cacheBackend
        ->delete($this->groupTypePluginMapCacheKey);
    }
    $this->pluginGroupContentTypeMap = NULL;
    $this->groupTypePluginMap = NULL;

    // Also clear the array of per group type plugin collections as it shares
    // its cache clearing requirements with the group type plugin map.
    $this->groupTypeInstalled = [];
  }

  /**
   * {@inheritdoc}
   */
  public function clearCachedDefinitions() {
    parent::clearCachedDefinitions();

    // The collection of all plugins should only change if the plugin
    // definitions change, so we can safely reset that here.
    $this->allPlugins = NULL;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DefaultPluginManager::$additionalAnnotationNamespaces protected property Additional namespaces the annotation discovery mechanism should scan for annotation definitions.
DefaultPluginManager::$alterHook protected property Name of the alter hook if one should be invoked.
DefaultPluginManager::$cacheKey protected property The cache key.
DefaultPluginManager::$cacheTags protected property An array of cache tags to use for the cached definitions.
DefaultPluginManager::$defaults protected property A set of defaults to be referenced by $this->processDefinition() if additional processing of plugins is necessary or helpful for development purposes. 9
DefaultPluginManager::$moduleHandler protected property The module handler to invoke the alter hook. 1
DefaultPluginManager::$namespaces protected property An object that implements \Traversable which contains the root paths keyed by the corresponding namespace to look for plugin implementations.
DefaultPluginManager::$pluginDefinitionAnnotationName protected property The name of the annotation that contains the plugin definition.
DefaultPluginManager::$pluginInterface protected property The interface each plugin should implement. 1
DefaultPluginManager::$subdir protected property The subdirectory within a namespace to look for plugins, or FALSE if the plugins are in the top level of the namespace.
DefaultPluginManager::alterDefinitions protected function Invokes the hook to alter the definitions if the alter hook is set. 1
DefaultPluginManager::alterInfo protected function Sets the alter hook name.
DefaultPluginManager::extractProviderFromDefinition protected function Extracts the provider from a plugin definition.
DefaultPluginManager::findDefinitions protected function Finds plugin definitions. 7
DefaultPluginManager::getCacheContexts public function The cache contexts associated with this object. Overrides CacheableDependencyInterface::getCacheContexts
DefaultPluginManager::getCachedDefinitions protected function Returns the cached plugin definitions of the decorated discovery class.
DefaultPluginManager::getCacheMaxAge public function The maximum age for which this object may be cached. Overrides CacheableDependencyInterface::getCacheMaxAge
DefaultPluginManager::getCacheTags public function The cache tags associated with this object. Overrides CacheableDependencyInterface::getCacheTags
DefaultPluginManager::getDefinitions public function Gets the definition of all plugins for this type. Overrides DiscoveryTrait::getDefinitions 2
DefaultPluginManager::getDiscovery protected function Gets the plugin discovery. Overrides PluginManagerBase::getDiscovery 12
DefaultPluginManager::getFactory protected function Gets the plugin factory. Overrides PluginManagerBase::getFactory
DefaultPluginManager::processDefinition public function Performs extra processing on plugin definitions. 13
DefaultPluginManager::providerExists protected function Determines if the provider of a definition exists. 3
DefaultPluginManager::setCacheBackend public function Initialize the cache backend.
DefaultPluginManager::setCachedDefinitions protected function Sets a cache of plugin definitions for the decorated discovery class.
DefaultPluginManager::useCaches public function Disable the use of caches. Overrides CachedDiscoveryInterface::useCaches 1
DiscoveryCachedTrait::$definitions protected property Cached definitions array. 1
DiscoveryCachedTrait::getDefinition public function Overrides DiscoveryTrait::getDefinition 3
DiscoveryTrait::doGetDefinition protected function Gets a specific plugin definition.
DiscoveryTrait::hasDefinition public function
GroupRelationManager::$allPlugins protected property A collection of vanilla instances of all group relation plugins.
GroupRelationManager::$entityTypeManager protected property The entity type manager.
GroupRelationManager::$groupContentTypeStorage protected property A group content type storage handler.
GroupRelationManager::$groupTypeInstalled protected property An list each group type's installed plugins as plugin collections.
GroupRelationManager::$groupTypePluginMap protected property An static cache of plugin IDs per group type ID.
GroupRelationManager::$groupTypePluginMapCacheKey protected property The cache key for the plugin IDs per group type ID map.
GroupRelationManager::$groupTypeStorage protected property The group type storage handler.
GroupRelationManager::$handlers protected property Contains instantiated handlers keyed by handler type and plugin ID.
GroupRelationManager::$pluginGroupContentTypeMap protected property An static cache of group content type IDs per plugin ID.
GroupRelationManager::$pluginGroupContentTypeMapCacheKey protected property The cache key for the group content type IDs per plugin ID map.
GroupRelationManager::clearCachedDefinitions public function Clears static and persistent plugin definition caches. Overrides DefaultPluginManager::clearCachedDefinitions
GroupRelationManager::clearCachedGroupTypeCollections public function Clears the static per group type plugin collection cache. Overrides GroupRelationManagerInterface::clearCachedGroupTypeCollections
GroupRelationManager::clearCachedPluginMaps public function Clears static and persistent plugin ID map caches. Overrides GroupRelationManagerInterface::clearCachedPluginMaps
GroupRelationManager::createHandlerInstance public function Creates a new handler instance. Overrides GroupRelationManagerInterface::createHandlerInstance
GroupRelationManager::getAccessControlHandler public function Creates a new access control handler instance. Overrides GroupRelationManagerInterface::getAccessControlHandler
GroupRelationManager::getAll public function Returns a plugin collection of all available group relations. Overrides GroupRelationManagerInterface::getAll
GroupRelationManager::getCachedGroupTypePluginMap protected function Returns the cached group type plugin map.
GroupRelationManager::getCachedPluginGroupContentTypeMap protected function Returns the cached group content type ID map.
GroupRelationManager::getGroupContentTypeIds public function Retrieves all of the group content type IDs for a content plugin. Overrides GroupRelationManagerInterface::getGroupContentTypeIds
GroupRelationManager::getGroupContentTypeStorage protected function Returns the group content type storage handler.
GroupRelationManager::getGroupTypeInstalled protected function Retrieves fully instantiated plugins for a group type.
GroupRelationManager::getGroupTypePluginMap public function Retrieves a list of plugin IDs per group type ID. Overrides GroupRelationManagerInterface::getGroupTypePluginMap
GroupRelationManager::getGroupTypeStorage protected function Returns the group type storage handler.
GroupRelationManager::getHandler public function Returns a handler instance for the given plugin and handler. Overrides GroupRelationManagerInterface::getHandler
GroupRelationManager::getInstalled public function Returns a plugin collection of all installed group relations. Overrides GroupRelationManagerInterface::getInstalled
GroupRelationManager::getInstalledIds public function Returns the plugin ID of all group relations in use. Overrides GroupRelationManagerInterface::getInstalledIds
GroupRelationManager::getPermissionProvider public function Creates a new permission provider instance. Overrides GroupRelationManagerInterface::getPermissionProvider
GroupRelationManager::getPluginGroupContentTypeMap public function Retrieves a list of group content type IDs per plugin ID. Overrides GroupRelationManagerInterface::getPluginGroupContentTypeMap
GroupRelationManager::getPluginIdsByEntityTypeAccess public function Returns the ID of all plugins that define access for a given entity type. Overrides GroupRelationManagerInterface::getPluginIdsByEntityTypeAccess
GroupRelationManager::getPostInstallHandler public function Creates a new post install handler instance. Overrides GroupRelationManagerInterface::getPostInstallHandler
GroupRelationManager::getVanillaInstalled protected function Retrieves a vanilla instance of every installed plugin.
GroupRelationManager::installEnforced public function Installs all plugins which are marked as enforced. Overrides GroupRelationManagerInterface::installEnforced
GroupRelationManager::setCachedGroupTypePluginMap protected function Sets a cache of the group type plugin map.
GroupRelationManager::setCachedPluginGroupContentTypeMap protected function Sets a cache of the group content type ID map.
GroupRelationManager::__construct public function Constructs a GroupRelationManager object. Overrides DefaultPluginManager::__construct
PluginManagerBase::$discovery protected property The object that discovers plugins managed by this manager.
PluginManagerBase::$factory protected property The object that instantiates plugins managed by this manager.
PluginManagerBase::$mapper protected property The object that returns the preconfigured plugin instance appropriate for a particular runtime condition.
PluginManagerBase::createInstance public function Creates a pre-configured instance of a plugin. Overrides FactoryInterface::createInstance 12
PluginManagerBase::getInstance public function Gets a preconfigured instance of a plugin. Overrides MapperInterface::getInstance 6
PluginManagerBase::handlePluginNotFound protected function Allows plugin managers to specify custom behavior if a plugin is not found. 1
UseCacheBackendTrait::$cacheBackend protected property Cache backend instance.
UseCacheBackendTrait::$useCaches protected property Flag whether caches should be used or skipped.
UseCacheBackendTrait::cacheGet protected function Fetches from the cache backend, respecting the use caches flag.
UseCacheBackendTrait::cacheSet protected function Stores data in the persistent cache, respecting the use caches flag.