-
-
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.
- Loading branch information
1 parent
a84b4b6
commit 3053707
Showing
6 changed files
with
222 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the Nette Framework (https://nette.org) | ||
* Copyright (c) 2004 David Grudl (https://davidgrudl.com) | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Nette\Caching; | ||
|
||
|
||
/** | ||
* Cache storage with a bulk write support. | ||
*/ | ||
interface BulkWriter | ||
{ | ||
/** | ||
* Writes to cache in bulk. | ||
* @param array{string, mixed} $items | ||
*/ | ||
function bulkWrite(array $items, array $dependencies): void; | ||
|
||
/** | ||
* Removes multiple items from cache | ||
*/ | ||
function bulkRemove(array $keys): void; | ||
} |
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
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,45 @@ | ||
<?php | ||
|
||
/** | ||
* Test: Nette\Caching\Cache save(). | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
use Nette\Caching\Cache; | ||
use Tester\Assert; | ||
|
||
require __DIR__ . '/../bootstrap.php'; | ||
require __DIR__ . '/Cache.php'; | ||
|
||
|
||
test('storage without bulk write support', function () { | ||
$storage = new TestStorage; | ||
$cache = new Cache($storage, 'ns'); | ||
$cache->bulkSave([1 => 'value1', 2 => 'value2']); | ||
|
||
$data = $cache->bulkLoad([1, 2]); | ||
Assert::same('value1', $data[1]['data']); | ||
Assert::same('value2', $data[2]['data']); | ||
}); | ||
|
||
test('storage with bulk write support', function () { | ||
$storage = new BulkWriteTestStorage; | ||
$cache = new Cache($storage, 'ns'); | ||
$cache->bulkSave([1 => 'value1', 2 => 'value2']); | ||
|
||
$data = $cache->bulkLoad([1, 2]); | ||
Assert::same('value1', $data[1]['data']); | ||
Assert::same('value2', $data[2]['data']); | ||
}); | ||
|
||
test('dependencies', function () { | ||
$storage = new BulkWriteTestStorage; | ||
$cache = new Cache($storage, 'ns'); | ||
$dependencies = [Cache::Tags => ['tag']]; | ||
$cache->bulkSave([1 => 'value1', 2 => 'value2'], $dependencies); | ||
|
||
$data = $cache->bulkLoad([1, 2]); | ||
Assert::same($dependencies, $data[1]['dependencies']); | ||
Assert::same($dependencies, $data[2]['dependencies']); | ||
}); |
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,36 @@ | ||
<?php | ||
|
||
/** | ||
* Test: Nette\Caching\Storages\MemcachedStorage and bulkWrite | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
use Nette\Caching\Cache; | ||
use Nette\Caching\Storages\MemcachedStorage; | ||
use Nette\Caching\Storages\SQLiteJournal; | ||
use Tester\Assert; | ||
|
||
require __DIR__ . '/../bootstrap.php'; | ||
|
||
|
||
if (!MemcachedStorage::isAvailable()) { | ||
Tester\Environment::skip('Requires PHP extension Memcached.'); | ||
} | ||
|
||
Tester\Environment::lock('memcached-files', getTempDir()); | ||
|
||
|
||
$storage = new MemcachedStorage('localhost', 11211, '', new SQLiteJournal(getTempDir() . '/journal-memcached.s3db')); | ||
$cache = new Cache($storage); | ||
|
||
//standard | ||
$cache->bulkSave(['foo' => 'bar']); | ||
Assert::same(['foo' => 'bar', 'lorem' => null], $cache->bulkLoad(['foo', 'lorem'])); | ||
|
||
//tags | ||
$dependencies = [Cache::Tags => ['tag']]; | ||
$cache->bulkSave(['foo' => 'bar'], $dependencies); | ||
Assert::same(['foo' => 'bar'], $cache->bulkLoad(['foo'])); | ||
$cache->clean($dependencies); | ||
Assert::same(['foo' => null], $cache->bulkLoad(['foo'])); |