-
-
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.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
10 changed files
with
307 additions
and
3 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,24 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the Nette Framework (https://nette.org) | ||
* Copyright (c) 2004 David Grudl (https://davidgrudl.com) | ||
*/ | ||
|
||
namespace Nette\Caching; | ||
|
||
|
||
/** | ||
* Cache storage with a bulk read support. | ||
*/ | ||
interface IBulkReader | ||
{ | ||
|
||
/** | ||
* Reads from cache in bulk. | ||
* @param string key | ||
* @return array key => value pairs, missing items are omitted | ||
*/ | ||
function bulkRead(array $keys); | ||
|
||
} |
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,64 @@ | ||
<?php | ||
|
||
/** | ||
* Test: Nette\Caching\Cache load(). | ||
*/ | ||
|
||
use Nette\Caching\Cache; | ||
use Tester\Assert; | ||
|
||
|
||
require __DIR__ . '/../bootstrap.php'; | ||
|
||
require __DIR__ . '/Cache.php'; | ||
|
||
// storage without bulk load support | ||
test(function () { | ||
$storage = new TestStorage; | ||
$cache = new Cache($storage, 'ns'); | ||
Assert::same([1 => NULL, 2 => NULL], $cache->bulkLoad([1, 2]), 'data'); | ||
|
||
Assert::same([1 => 1, 2 => 2], $cache->bulkLoad([1, 2], function ($key) { | ||
return $key; | ||
})); | ||
|
||
$data = $cache->bulkLoad([1, 2]); | ||
Assert::same(1, $data[1]['data']); | ||
Assert::same(2, $data[2]['data']); | ||
}); | ||
|
||
// storage with bulk load support | ||
test(function () { | ||
$storage = new BulkReadTestStorage; | ||
$cache = new Cache($storage, 'ns'); | ||
Assert::same([1 => NULL, 2 => NULL], $cache->bulkLoad([1, 2])); | ||
|
||
Assert::same([1 => 1, 2 => 2], $cache->bulkLoad([1, 2], function ($key) { | ||
return $key; | ||
})); | ||
|
||
$data = $cache->bulkLoad([1, 2]); | ||
Assert::same(1, $data[1]['data']); | ||
Assert::same(2, $data[2]['data']); | ||
}); | ||
|
||
// dependencies | ||
test(function () { | ||
$storage = new BulkReadTestStorage; | ||
$cache = new Cache($storage, 'ns'); | ||
$dependencies = [Cache::TAGS => 'tag']; | ||
$cache->bulkLoad([1], function ($key, & $deps) use ($dependencies) { | ||
$deps = $dependencies; | ||
return $key; | ||
}); | ||
|
||
$data = $cache->bulkLoad([1, 2]); | ||
Assert::same($dependencies, $data[1]['dependencies']); | ||
}); | ||
|
||
test(function () { | ||
Assert::exception(function () { | ||
$cache = new Cache(new BulkReadTestStorage()); | ||
$cache->bulkLoad([[1]]); | ||
}, Nette\InvalidArgumentException::class, 'Only scalar keys are allowed in bulkLoad()'); | ||
}); |
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,27 @@ | ||
<?php | ||
|
||
/** | ||
* Test: Nette\Caching\Storages\NewMemcachedStorage and bulkRead | ||
*/ | ||
|
||
use Nette\Caching\Storages\NewMemcachedStorage; | ||
use Nette\Caching\Cache; | ||
use Tester\Assert; | ||
|
||
|
||
require __DIR__ . '/../bootstrap.php'; | ||
|
||
|
||
if (!NewMemcachedStorage::isAvailable()) { | ||
Tester\Environment::skip('Requires PHP extension Memcached.'); | ||
} | ||
|
||
Tester\Environment::lock('memcached-files', TEMP_DIR); | ||
|
||
|
||
|
||
$cache = new Cache(new NewMemcachedStorage('localhost')); | ||
|
||
$cache->save('foo', 'bar'); | ||
|
||
Assert::same(['foo' => 'bar', 'lorem' => NULL], $cache->bulkLoad(['foo', 'lorem'])); |
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,23 @@ | ||
<?php | ||
|
||
/** | ||
* Test: Nette\Caching\Storages\SQLiteStorage and bulk read. | ||
*/ | ||
|
||
use Nette\Caching\Cache; | ||
use Nette\Caching\Storages\SQLiteStorage; | ||
use Tester\Assert; | ||
|
||
|
||
require __DIR__ . '/../bootstrap.php'; | ||
|
||
|
||
if (!extension_loaded('pdo_sqlite')) { | ||
Tester\Environment::skip('Requires PHP extension pdo_sqlite.'); | ||
} | ||
|
||
|
||
$cache = new Cache(new SQLiteStorage(':memory:')); | ||
$cache->save('foo', 'bar'); | ||
|
||
Assert::same(['foo' => 'bar', 'lorem' => NULL], $cache->bulkLoad(['foo', 'lorem'])); |
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