Neos\Cache\Backend\MemcachedBackend::flush PHP Method

flush() public method

Removes all cache entries of this cache.
public flush ( ) : void
return void
    public function flush()
    {
        if (!$this->cache instanceof FrontendInterface) {
            throw new Exception('Yet no cache frontend has been set via setCache().', 1204111376);
        }
        $this->flushByTag('%MEMCACHEBE%' . $this->cacheIdentifier);
    }

Usage Example

 /**
  * @test
  */
 public function flushRemovesOnlyOwnEntries()
 {
     $backendOptions = ['servers' => ['localhost:11211']];
     $thisCache = $this->getMockBuilder(AbstractFrontend::class)->disableOriginalConstructor()->getMock();
     $thisCache->expects($this->any())->method('getIdentifier')->will($this->returnValue('thisCache'));
     $thisBackend = new MemcachedBackend($this->getEnvironmentConfiguration(), $backendOptions);
     $thisBackend->setCache($thisCache);
     $thatCache = $this->getMockBuilder(AbstractFrontend::class)->disableOriginalConstructor()->getMock();
     $thatCache->expects($this->any())->method('getIdentifier')->will($this->returnValue('thatCache'));
     $thatBackend = new MemcachedBackend($this->getEnvironmentConfiguration(), $backendOptions);
     $thatBackend->setCache($thatCache);
     $thisBackend->set('thisEntry', 'Hello');
     $thatBackend->set('thatEntry', 'World!');
     $thatBackend->flush();
     $this->assertEquals('Hello', $thisBackend->get('thisEntry'));
     $this->assertFalse($thatBackend->has('thatEntry'));
 }