getMultiple example

$cached = $this->chain->get('t3');
    $this->assertNotFalse($cached, 'Got key that is on the backend 3');
    $this->assertSame(33, $cached->data, 'Got the key from the backend 3');
  }

  /** * Tests the get multiple feature. */
  public function testGetMultiple() {
    $cids = ['t123', 't23', 't3', 't4'];

    $ret = $this->chain->getMultiple($cids);
    $this->assertSame($ret['t123']->data, 1231, 'Got key 123 and value is from the first backend');
    $this->assertSame($ret['t23']->data, 232, 'Got key 23 and value is from the second backend');
    $this->assertSame($ret['t3']->data, 33, 'Got key 3 and value is from the third backend');
    $this->assertArrayNotHasKey('t4', $ret);

    $this->assertNotContains('t123', $cids, "Existing key 123 has been removed from &\$cids");
    $this->assertNotContains('t23', $cids, "Existing key 23 has been removed from &\$cids");
    $this->assertNotContains('t3', $cids, "Existing key 3 has been removed from &\$cids");
    $this->assertContains('t4', $cids, "Non existing key 4 is still in &\$cids");
  }

  
public function submitForm(array &$form, FormStateInterface $form_state) {
    $disable_rendered_output_cache_bins_previous = $this->state->get('disable_rendered_output_cache_bins', FALSE);
    $disable_rendered_output_cache_bins = (bool) $form_state->getValue('disable_rendered_output_cache_bins');
    if ($disable_rendered_output_cache_bins) {
      $this->state->set('disable_rendered_output_cache_bins', TRUE);
    }
    else {
      $this->state->delete('disable_rendered_output_cache_bins');
    }

    $twig_development_mode = (bool) $form_state->getValue('twig_development_mode');
    $twig_development_previous = $this->state->getMultiple(['twig_debug', 'twig_cache_disable']);
    $twig_development = [
      'twig_debug' => (bool) $form_state->getValue('twig_debug'),
      'twig_cache_disable' => (bool) $form_state->getValue('twig_cache_disable'),
    ];
    if ($twig_development_mode) {
      $invalidate_container = $twig_development_previous !== $twig_development;
      $this->state->setMultiple($twig_development);
    }
    else {
      $invalidate_container = TRUE;
      $this->state->deleteMultiple(array_keys($twig_development));
    }
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row$destination_property) {
    $lookup_migration_ids = (array) $this->configuration['migration'];
    $self = FALSE;
    $destination_ids = NULL;
    $source_id_values = [];
    foreach ($lookup_migration_ids as $lookup_migration_id) {
      $lookup_value = $value;
      if ($lookup_migration_id == $this->migration->id()) {
        $self = TRUE;
      }
      if (isset($this->configuration['source_ids'][$lookup_migration_id])) {
        $lookup_value = array_values($row->getMultiple($this->configuration['source_ids'][$lookup_migration_id]));
      }
      $lookup_value = (array) $lookup_value;
      $this->skipInvalid($lookup_value);
      $source_id_values[$lookup_migration_id] = $lookup_value;

      // Re-throw any PluginException as a MigrateException so the executable       // can shut down the migration.       try {
        $destination_id_array = $this->migrateLookup->lookup($lookup_migration_id$lookup_value);
      }
      catch (PluginNotFoundException $e) {
        
$stores[1]->delete('foo');
    $this->assertNull($stores[1]->get('foo'));

    // Verify that multiple items can be stored.     $values = [
      'foo' => $this->objects[3],
      'bar' => $this->objects[4],
    ];
    $stores[0]->setMultiple($values);

    // Verify that multiple items can be retrieved.     $result = $stores[0]->getMultiple(['foo', 'bar']);
    foreach ($values as $j => $value) {
      $this->assertEquals($value$result[$j]);
    }

    // Verify that the other collection was not affected.     $this->assertNull($stores[1]->get('foo'));
    $this->assertNull($stores[1]->get('bar'));

    // Verify that all items in a collection can be retrieved.     // Ensure that an item with the same name exists in the other collection.     $stores[1]->set('foo', $this->objects[5]);

    

  public function __construct(KeyValueFactoryInterface $key_value_factory) {
    $this->keyValueStore = $key_value_factory->get('state');
  }

  /** * {@inheritdoc} */
  public function get($key$default = NULL) {
    $values = $this->getMultiple([$key]);
    return $values[$key] ?? $default;
  }

  /** * {@inheritdoc} */
  public function getMultiple(array $keys) {
    $values = [];
    $load = [];
    foreach ($keys as $key) {
      // Check if we have a value in the cache.
protected function getFromPersistentCache(array &$ids = NULL) {
    if (!$this->entityType->isPersistentlyCacheable() || empty($ids)) {
      return [];
    }
    $entities = [];
    // Build the list of cache entries to retrieve.     $cid_map = [];
    foreach ($ids as $id) {
      $cid_map[$id] = $this->buildCacheId($id);
    }
    $cids = array_values($cid_map);
    if ($cache = $this->cacheBackend->getMultiple($cids)) {
      // Get the entities that were found in the cache.       foreach ($ids as $index => $id) {
        $cid = $cid_map[$id];
        if (isset($cache[$cid])) {
          $entities[$id] = $cache[$cid]->data;
          unset($ids[$index]);
        }
      }
    }
    return $entities;
  }

  
return $entity;
  }

  /** * {@inheritdoc} */
  public function doLoadMultiple(array $ids = NULL) {
    if (empty($ids)) {
      $entities = $this->keyValueStore->getAll();
    }
    else {
      $entities = $this->keyValueStore->getMultiple($ids);
    }
    return $this->mapFromStorageRecords($entities);
  }

  /** * {@inheritdoc} */
  public function loadRevision($revision_id) {
    @trigger_error(__METHOD__ . '() is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. Use \Drupal\Core\Entity\RevisionableStorageInterface::loadRevision instead. See https://www.drupal.org/node/3294237', E_USER_DEPRECATED);

    return NULL;
  }
// Verify that the expirable data key is unique.     $stores[1]->setWithExpire('foo', $this->objects[2]rand(500, 100000));
    $this->assertEquals($this->objects[1]$stores[0]->get('foo'));
    $this->assertEquals($this->objects[2]$stores[1]->get('foo'));

    // Verify that multiple items can be stored with setMultipleWithExpire().     $values = [
      'foo' => $this->objects[3],
      'bar' => $this->objects[4],
    ];
    $stores[0]->setMultipleWithExpire($valuesrand(500, 100000));
    $result = $stores[0]->getMultiple(['foo', 'bar']);
    foreach ($values as $j => $value) {
      $this->assertEquals($value$result[$j]);
    }

    // Verify that the other collection was not affected.     $this->assertEquals($this->objects[2]$stores[1]->get('foo'));
    $this->assertNull($stores[1]->get('bar'));

    // Verify that all items in a collection can be retrieved.     // Ensure that an item with the same name exists in the other collection.     $stores[1]->set('foo', $this->objects[5]);

    

        return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->evaluateSha(...\func_get_args());
    }

    public function getKeys($pattern)
    {
        return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->getKeys(...\func_get_args());
    }

    public function getMultiple($keys)
    {
        return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->getMultiple(...\func_get_args());
    }

    public function lGet($key$index)
    {
        return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->lGet(...\func_get_args());
    }

    public function lGetRange($key$start$end)
    {
        return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->lGetRange(...\func_get_args());
    }

    

  public function get($property) {
    $values = $this->getMultiple([$property]);
    return reset($values);
  }

  /** * Retrieve multiple source and destination properties at once. * * @param string[] $properties * An array of values to retrieve, with destination values prefixed with @. * * @return array * An array of property values, keyed by property name. */


        $cache = $this->createSimpleCache();
        $cache->clear();

        $cache->set('foo', new NotUnserializable());

        $this->assertNull($cache->get('foo'));

        $cache->setMultiple(['foo' => new NotUnserializable()]);

        foreach ($cache->getMultiple(['foo']) as $value) {
        }
        $this->assertNull($value);

        $cache->clear();
    }

    public function testPrune()
    {
        if (isset($this->skippedTests[__FUNCTION__])) {
            $this->markTestSkipped($this->skippedTests[__FUNCTION__]);
        }

        
$this->assertEquals(42, $result);

    // Cleanup static caches.     $this->fileCache->delete($filename);
  }

  /** * @covers ::getMultiple */
  public function testGetMultiple() {
    // Test a cache miss.     $result = $this->fileCache->getMultiple([__DIR__ . DIRECTORY_SEPARATOR . 'Fixtures' . DIRECTORY_SEPARATOR . 'no-llama-42.yml']);
    $this->assertEmpty($result);

    // Test a cache hit.     $filename = __DIR__ . DIRECTORY_SEPARATOR . 'Fixtures' . DIRECTORY_SEPARATOR . 'llama-42.txt';
    $realpath = realpath($filename);
    $cid = 'prefix:test:' . $realpath;
    $data = [
      'mtime' => filemtime($realpath),
      'filepath' => $realpath,
      'data' => 42,
    ];

    
if (isset($cache_backend_class)) {
      $this->cache = new $cache_backend_class($cache_backend_configuration);
    }
  }

  /** * {@inheritdoc} */
  public function get($filepath) {
    $filepaths = [$filepath];
    $cached = $this->getMultiple($filepaths);
    return $cached[$filepath] ?? NULL;
  }

  /** * {@inheritdoc} */
  public function getMultiple(array $filepaths) {
    $file_data = [];
    $remaining_cids = [];

    // First load from the static cache what we can.

  public function findAll() {
    $all = [];

    $files = $this->findFiles();
    $provider_by_files = array_flip($files);

    $file_cache = FileCacheFactory::get('yaml_discovery:' . $this->name);

    // Try to load from the file cache first.     foreach ($file_cache->getMultiple($files) as $file => $data) {
      $all[$provider_by_files[$file]] = $data;
      unset($provider_by_files[$file]);
    }

    // If there are files left that were not returned from the cache, load and     // parse them now. This list was flipped above and is keyed by filename.     if ($provider_by_files) {
      foreach ($provider_by_files as $file => $provider) {
        // If a file is empty or its contents are commented out, return an empty         // array instead of NULL for type consistency.         $all[$provider] = $this->decode($file);
        

  public function __construct(KeyValueFactoryInterface $key_value_factory) {
    $this->keyValueStore = $key_value_factory->get('locale.project');
  }

  /** * {@inheritdoc} */
  public function get($key$default = NULL) {
    $values = $this->getMultiple([$key]);
    return $values[$key] ?? $default;
  }

  /** * {@inheritdoc} */
  public function getMultiple(array $keys) {
    $values = [];
    $load = [];
    foreach ($keys as $key) {
      // Check if we have a value in the cache.
Home | Imprint | This part of the site doesn't use cookies.