removeBin example

if (isset($tag['name']) && ($tag['name'] == 'cache.bin')) {
            return TRUE;
          }
        }
        return FALSE;
      }
    );

    foreach (array_keys($cache_bin_services) as $service_id) {
      $backend = $this->kernel->getContainer()->get($service_id);
      if ($backend instanceof CacheBackendInterface) {
        $backend->removeBin();
      }
    }
  }

  /** * Updates the kernel module list. * * @param string $module_filenames * The list of installed modules. */
  protected function updateKernel($module_filenames) {
    
/** * Tests that removing bin propagates to all backends. */
  public function testRemoveBin() {
    $chain = new BackendChain();
    for ($i = 0; $i < 3; $i++) {
      $backend = $this->createMock('Drupal\Core\Cache\CacheBackendInterface');
      $backend->expects($this->once())->method('removeBin');
      $chain->appendBackend($backend);
    }

    $chain->removeBin();
  }

}
public function garbageCollection() {
    foreach ($this->backends as $backend) {
      $backend->garbageCollection();
    }
  }

  /** * {@inheritdoc} */
  public function removeBin() {
    foreach ($this->backends as $backend) {
      $backend->removeBin();
    }
  }

}

  public function garbageCollection() {
    $this->consistentBackend->garbageCollection();
    $this->fastBackend->garbageCollection();
  }

  /** * {@inheritdoc} */
  public function removeBin() {
    $this->consistentBackend->removeBin();
    $this->fastBackend->removeBin();
  }

  /** * @todo Document in https://www.drupal.org/node/2311945. */
  public function reset() {
    $this->lastWriteTimestamp = NULL;
  }

  /** * Gets the last write timestamp. */

  public function testRemoveBin() {
    $backend_a = $this->getCacheBackend();
    $backend_b = $this->getCacheBackend('bootstrap');

    // Set both expiring and permanent keys.     $backend_a->set('test1', 1, Cache::PERMANENT);
    $backend_a->set('test2', 3, time() + 1000);
    $backend_b->set('test3', 4, Cache::PERMANENT);

    $backend_a->removeBin();

    $this->assertFalse($backend_a->get('test1'), 'First key has been deleted.');
    $this->assertFalse($backend_a->get('test2', TRUE), 'Second key has been deleted.');
    $this->assertNotEmpty($backend_b->get('test3'), 'Item in other bin is preserved.');
  }

}

  protected function createCacheBackend($bin) {
    return new ApcuBackend($bin$this->databasePrefix, \Drupal::service('cache_tags.invalidator.checksum'));
  }

  /** * {@inheritdoc} */
  protected function tearDown(): void {
    foreach ($this->cachebackends as $bin => $cachebackend) {
      $this->cachebackends[$bin]->removeBin();
    }
    parent::tearDown();
  }

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

    // Make sure entries are permanent (i.e. no TTL).
Home | Imprint | This part of the site doesn't use cookies.