|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * Test: Nette\Caching\Cache save(). |
| 5 | + */ |
| 6 | + |
| 7 | +declare(strict_types=1); |
| 8 | + |
| 9 | +use Nette\Caching\Cache; |
| 10 | +use Tester\Assert; |
| 11 | + |
| 12 | +require __DIR__ . '/../bootstrap.php'; |
| 13 | +require __DIR__ . '/Cache.php'; |
| 14 | + |
| 15 | + |
| 16 | +test('storage without bulk write support', function () { |
| 17 | + $storage = new TestStorage; |
| 18 | + $cache = new Cache($storage, 'ns'); |
| 19 | + Assert::same([1, 2], $cache->bulkSave([1, 2]), 'data'); |
| 20 | + Assert::same([1 => 'value1', 2 => 'value2'], $cache->bulkSave([1 => 'value1', 2 => 'value2']), 'data'); |
| 21 | + |
| 22 | + $data = $cache->bulkLoad([1, 2]); |
| 23 | + Assert::same('value1', $data[1]['data']); |
| 24 | + Assert::same('value2', $data[2]['data']); |
| 25 | +}); |
| 26 | + |
| 27 | +test('storage with bulk write support', function () { |
| 28 | + $storage = new BulkWriteTestStorage; |
| 29 | + $cache = new Cache($storage, 'ns'); |
| 30 | + Assert::same([1, 2], $cache->bulkSave([1, 2]), 'data'); |
| 31 | + Assert::same([1 => 'value1', 2 => 'value2'], $cache->bulkSave([1 => 'value1', 2 => 'value2']), 'data'); |
| 32 | + |
| 33 | + $data = $cache->bulkLoad([1, 2]); |
| 34 | + Assert::same('value1', $data[1]['data']); |
| 35 | + Assert::same('value2', $data[2]['data']); |
| 36 | +}); |
| 37 | + |
| 38 | +test('dependencies', function () { |
| 39 | + $storage = new BulkWriteTestStorage; |
| 40 | + $cache = new Cache($storage, 'ns'); |
| 41 | + $dependencies = [Cache::Tags => ['tag']]; |
| 42 | + $cache->bulkSave([1 => 'value1', 2 => 'value2'], $dependencies); |
| 43 | + |
| 44 | + $data = $cache->bulkLoad([1, 2]); |
| 45 | + Assert::same($dependencies, $data[1]['dependencies']); |
| 46 | + Assert::same($dependencies, $data[2]['dependencies']); |
| 47 | + |
| 48 | + $cache->clean($dependencies); |
| 49 | + |
| 50 | + Assert::same([1 => null, 2 => null], $cache->bulkLoad([1, 2])); |
| 51 | +}); |
0 commit comments