-
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SQLiteStorage: added support for cleaning namespace
- Loading branch information
Showing
2 changed files
with
112 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?php | ||
|
||
/** | ||
* Test: Nette\Caching\Storages\SQLiteStorage clean with Cache::NAMESPACE | ||
* @phpExtension pdo_sqlite | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
use Nette\Caching\Cache; | ||
use Nette\Caching\Storages\SQLiteStorage; | ||
use Tester\Assert; | ||
|
||
|
||
require __DIR__ . '/../bootstrap.php'; | ||
|
||
$storage = new SQLiteStorage(':memory:'); | ||
|
||
/* | ||
* Create SQLiteStorage cache without namespace and some with namespaces | ||
*/ | ||
$cacheA = new Cache($storage); | ||
$cacheB = new Cache($storage, 'C' . Cache::NAMESPACE_SEPARATOR . 'A'); | ||
$cacheC = new Cache($storage, 'C'); | ||
$cacheD = new Cache($storage, 'D'); | ||
|
||
/* | ||
* Fill with data | ||
*/ | ||
$cacheA->save('test1', 'David'); | ||
$cacheA->save('test2', 'Grudl'); | ||
|
||
$cacheB->save('test1', 'Barry'); | ||
$cacheB->save('test2', 'Allen'); | ||
|
||
$cacheC->save('test1', 'Oliver'); | ||
$cacheC->save('test2', 'Queen'); | ||
|
||
$cacheD->save('test1', 'Bruce'); | ||
$cacheD->save('test2', 'Wayne'); | ||
|
||
|
||
/* | ||
* Check if fill wass successfull | ||
*/ | ||
Assert::same('David', $cacheA->load('test1')); | ||
Assert::same('Grudl', $cacheA->load('test2')); | ||
|
||
Assert::same('Barry', $cacheB->load('test1')); | ||
Assert::same('Allen', $cacheB->load('test2')); | ||
|
||
Assert::same('Oliver', $cacheC->load('test1')); | ||
Assert::same('Queen', $cacheC->load('test2')); | ||
|
||
Assert::same('Bruce', $cacheD->load('test1')); | ||
Assert::same('Wayne', $cacheD->load('test2')); | ||
|
||
|
||
/* | ||
* Clean one namespace | ||
*/ | ||
$storage->clean([Cache::NAMESPACES => [$cacheB->getNamespace()]]); | ||
|
||
Assert::same('David', $cacheA->load('test1')); | ||
Assert::same('Grudl', $cacheA->load('test2')); | ||
|
||
// Only these should be null now | ||
Assert::null($cacheB->load('test1')); | ||
Assert::null($cacheB->load('test2')); | ||
|
||
Assert::same('Oliver', $cacheC->load('test1')); | ||
Assert::same('Queen', $cacheC->load('test2')); | ||
|
||
Assert::same('Bruce', $cacheD->load('test1')); | ||
Assert::same('Wayne', $cacheD->load('test2')); | ||
|
||
|
||
/* | ||
* Test cleaning multiple namespaces | ||
*/ | ||
$storage->clean([Cache::NAMESPACES => [$cacheC->getNamespace(), $cacheD->getNamespace()]]); | ||
|
||
Assert::same('David', $cacheA->load('test1')); | ||
Assert::same('Grudl', $cacheA->load('test2')); | ||
|
||
// All other should be null | ||
Assert::null($cacheB->load('test1')); | ||
Assert::null($cacheB->load('test2')); | ||
|
||
Assert::null($cacheC->load('test1')); | ||
Assert::null($cacheC->load('test2')); | ||
|
||
Assert::null($cacheD->load('test1')); | ||
Assert::null($cacheD->load('test2')); |