Skip to content

Commit 8cb5d97

Browse files
committed
Merge branch 'release/2.2.0'
2 parents f2658d9 + 1cd902d commit 8cb5d97

File tree

2 files changed

+62
-9
lines changed

2 files changed

+62
-9
lines changed

src/Psr6Store.php

+15
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,21 @@ public function prune()
423423
}
424424
}
425425

426+
/**
427+
* {@inheritdoc}
428+
*/
429+
public function clear()
430+
{
431+
// Make sure we do not have multiple pruning processes running
432+
$lock = $this->lockFactory->createLock('clear-lock');
433+
434+
if ($lock->acquire()) {
435+
$this->cache->clear();
436+
437+
$lock->release();
438+
}
439+
}
440+
426441
/**
427442
* @return string
428443
*/

tests/Psr6StoreTest.php

+47-9
Original file line numberDiff line numberDiff line change
@@ -498,20 +498,58 @@ public function testInvalidate()
498498

499499
public function testPurge()
500500
{
501-
$request = Request::create('https://foobar.com/');
502-
$response = new Response('hello world', 200);
503-
$response->headers->set('Foobar', 'whatever');
501+
// Request 1
502+
$request1 = Request::create('https://foobar.com/');
503+
$response1 = new Response('hello world', 200);
504504

505-
$this->store->write($request, $response);
506-
$cacheKey = $this->store->getCacheKey($request);
505+
// Request 2
506+
$request2 = Request::create('https://foobar.com/foobar');
507+
$response2 = new Response('hello world', 200);
507508

508-
$cacheItem = $this->getCache()->getItem($cacheKey);
509-
$this->assertTrue($cacheItem->isHit());
509+
$this->store->write($request1, $response1);
510+
$this->store->write($request2, $response2);
511+
$cacheKey1 = $this->store->getCacheKey($request1);
512+
$cacheKey2 = $this->store->getCacheKey($request2);
513+
514+
$cacheItem1 = $this->getCache()->getItem($cacheKey1);
515+
$cacheItem2 = $this->getCache()->getItem($cacheKey2);
516+
$this->assertTrue($cacheItem1->isHit());
517+
$this->assertTrue($cacheItem2->isHit());
510518

511519
$this->store->purge('https://foobar.com/');
512520

513-
$cacheItem = $this->getCache()->getItem($cacheKey);
514-
$this->assertFalse($cacheItem->isHit());
521+
$cacheItem1 = $this->getCache()->getItem($cacheKey1);
522+
$cacheItem2 = $this->getCache()->getItem($cacheKey2);
523+
$this->assertFalse($cacheItem1->isHit());
524+
$this->assertTrue($cacheItem2->isHit());
525+
}
526+
527+
public function testClear()
528+
{
529+
// Request 1
530+
$request1 = Request::create('https://foobar.com/');
531+
$response1 = new Response('hello world', 200);
532+
533+
// Request 2
534+
$request2 = Request::create('https://foobar.com/foobar');
535+
$response2 = new Response('hello world', 200);
536+
537+
$this->store->write($request1, $response1);
538+
$this->store->write($request2, $response2);
539+
$cacheKey1 = $this->store->getCacheKey($request1);
540+
$cacheKey2 = $this->store->getCacheKey($request2);
541+
542+
$cacheItem1 = $this->getCache()->getItem($cacheKey1);
543+
$cacheItem2 = $this->getCache()->getItem($cacheKey2);
544+
$this->assertTrue($cacheItem1->isHit());
545+
$this->assertTrue($cacheItem2->isHit());
546+
547+
$this->store->clear();
548+
549+
$cacheItem1 = $this->getCache()->getItem($cacheKey1);
550+
$cacheItem2 = $this->getCache()->getItem($cacheKey2);
551+
$this->assertFalse($cacheItem1->isHit());
552+
$this->assertFalse($cacheItem2->isHit());
515553
}
516554

517555
public function testPruneIgnoredIfCacheBackendDoesNotImplementPrunableInterface()

0 commit comments

Comments
 (0)