-
Notifications
You must be signed in to change notification settings - Fork 15
/
test.php
55 lines (45 loc) · 1.54 KB
/
test.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
namespace Psr\Cache;
// This is strictly so that we can work on these packages without publishing
// them yet. This whole file will eventually be removed.
require_once '../psr-cache/vendor/autoload.php';
require_once 'vendor/autoload.php';
date_default_timezone_set('America/Chicago');
$pool = new MemoryPool();
// Basic set/get operations.
$item = $pool->getItem('foo');
$item->set('foo value', '300');
$pool->save($item);
$item = $pool->getItem('bar');
$item->set('bar value', new \DateTime('now + 5min'));
$pool->save($item);
foreach ($pool->getItems(['foo', 'bar']) as $key => $item) {
if ($key == 'foo') {
assert($item->get() == 'foo value');
}
if ($key == 'bar') {
assert($item->get() == 'bar value');
}
}
// Update an existing item.
$items = $pool->getItems(['foo', 'bar']);
$items['bar']->set('new bar value');
array_map([$pool, 'save'], $items);
foreach ($pool->getItems(['foo', 'bar']) as $item) {
if ($item->getKey() == 'foo') {
assert($item->get() == 'foo value');
}
if ($item->getKey() == 'bar') {
assert($item->get() == 'new bar value');
}
}
// Defer saving to a later operation.
$item = $pool->getItem('baz')->set('baz value', '100');
$pool->saveDeferred($item);
$item = $pool->getItem('foo')->set('new foo value', new \DateTime('now + 1min'));
$pool->saveDeferred($item);
$pool->commit();
$items = $pool->getItems(['foo', 'bar', 'baz']);
assert($items['foo']->get() == 'new foo value');
assert($items['bar']->get() == 'new bar value');
assert($items['baz']->get() == 'baz value');