useCaches example

$cache_backend = $this->getMockBuilder('Drupal\Core\Cache\MemoryBackend')
      ->disableOriginalConstructor()
      ->getMock();
    $cache_backend
      ->expects($this->never())
      ->method('get');
    $cache_backend
      ->expects($this->never())
      ->method('set');
    $plugin_manager->setCacheBackend($cache_backend$cid);

    $plugin_manager->useCaches(FALSE);

    $this->assertEquals($this->expectedDefinitions, $plugin_manager->getDefinitions());
    $this->assertEquals($this->expectedDefinitions['banana']$plugin_manager->getDefinition('banana'));
  }

  /** * Tests the plugin manager cache clear with tags. */
  public function testCacheClearWithTags() {
    $cid = $this->randomMachineName();
    $cache_backend = $this->createMock('Drupal\Core\Cache\CacheBackendInterface');
    

  public function uninstallFieldStorageDefinition(FieldStorageDefinitionInterface $storage_definition) {
    $this->clearCachedDefinitions();
    $this->fieldStorageDefinitionListener->onFieldStorageDefinitionDelete($storage_definition);
  }

  /** * {@inheritdoc} */
  public function getChangeList() {
    $this->entityTypeManager->useCaches(FALSE);
    $this->entityFieldManager->useCaches(FALSE);
    $change_list = [];

    foreach ($this->entityTypeManager->getDefinitions() as $entity_type_id => $entity_type) {
      $original = $this->entityLastInstalledSchemaRepository->getLastInstalledDefinition($entity_type_id);

      // @todo Support non-storage-schema-changing definition updates too:       // https://www.drupal.org/node/2336895.       if (!$original) {
        $change_list[$entity_type_id]['entity_type'] = static::DEFINITION_CREATED;
      }
      

  public function clearCachedDefinitions() {
    parent::clearCachedDefinitions();
    $this->handlers = [];
  }

  /** * {@inheritdoc} */
  public function useCaches($use_caches = FALSE) {
    parent::useCaches($use_caches);
    if (!$use_caches) {
      $this->handlers = [];
      $this->container->get('entity.memory_cache')->reset();
    }
  }

  /** * {@inheritdoc} */
  public function hasHandler($entity_type_id$handler_type) {
    if ($definition = $this->getDefinition($entity_type_id, FALSE)) {
      
->getItemDefinition()
      ->getFieldDefinition();

    // Load and execute a view.     $view_entity = View::load('content');
    $view_executable = $view_entity->getExecutable();
    $view_executable->execute('page_1');

    // Reset the static cache. Don't use clearCachedFieldDefinitions() since     // that clears the persistent cache and we need to get the serialized cache     // data.     $field_manager->useCaches(FALSE);
    $field_manager->useCaches(TRUE);

    // Serialize the ViewExecutable as part of other data.     unserialize(serialize(['SOMETHING UNEXPECTED', $view_executable]));

    // Make sure the serialization of the ViewExecutable didn't influence the     // field definitions.     $nid_definition_after = $field_manager->getBaseFieldDefinitions('node')['nid']
      ->getItemDefinition()
      ->getFieldDefinition();
    $this->assertEquals($nid_definition_before->getPropertyDefinitions()$nid_definition_after->getPropertyDefinitions());
  }
Home | Imprint | This part of the site doesn't use cookies.