Skip to content

Commit f64d2e5

Browse files
committed
Keys with no hierarchy works
1 parent 62aaaba commit f64d2e5

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
{
3030
"php": "^5.5|^7.0",
3131
"psr/cache": "1.0.0",
32+
"cache/adapter-common": "^0.1",
3233
"cache/taggable-cache": "^0.2"
3334
},
3435
"require-dev":

src/HierarchicalCachePool.php

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111

1212
namespace Cache\Hierarchy;
1313

14+
use Cache\Adapter\Common\Exception\InvalidArgumentException;
1415
use Cache\Taggable\TaggablePoolInterface;
1516
use Psr\Cache\CacheItemInterface;
1617
use Psr\Cache\CacheItemPoolInterface;
17-
use Psr\Cache\InvalidArgumentException;
1818

1919
/**
2020
* @author Tobias Nyholm <[email protected]>
@@ -45,6 +45,7 @@ public function getItem($key, array $tags = [])
4545
if (!$this->isHierarchyKey($key)) {
4646
return $this->cache->getItem($key, $tags);
4747
}
48+
4849
// TODO: Implement getItem() method.
4950
}
5051

@@ -53,10 +54,12 @@ public function getItem($key, array $tags = [])
5354
*/
5455
public function getItems(array $keys = [], array $tags = [])
5556
{
56-
if (!$this->isHierarchyKey($keys)) {
57-
return $this->cache->getItems($keys, $tags);
57+
$items = [];
58+
foreach ($keys as $key) {
59+
$items[$key] = $this->getItem($key, $tags);
5860
}
59-
// TODO: Implement getItems() method.
61+
62+
return $items;
6063
}
6164

6265
/**
@@ -94,34 +97,36 @@ public function deleteItem($key, array $tags = [])
9497
*/
9598
public function deleteItems(array $keys, array $tags = [])
9699
{
97-
if (!$this->isHierarchyKey($keys)) {
98-
return $this->cache->deleteItems($keys, $tags);
100+
$result = true;
101+
foreach ($keys as $key) {
102+
$result = $result && $this->deleteItem($key, $tags);
99103
}
100-
// TODO: Implement deleteItems() method.
104+
105+
return $result;
101106
}
102107

103108
/**
104109
* {@inheritdoc}
105110
*/
106111
public function save(CacheItemInterface $item)
107112
{
108-
$this->cache->save($item);
113+
return $this->cache->save($item);
109114
}
110115

111116
/**
112117
* {@inheritdoc}
113118
*/
114119
public function saveDeferred(CacheItemInterface $item)
115120
{
116-
$this->cache->saveDeferred($item);
121+
return $this->cache->saveDeferred($item);
117122
}
118123

119124
/**
120125
* {@inheritdoc}
121126
*/
122127
public function commit()
123128
{
124-
$this->cache->commit();
129+
return $this->cache->commit();
125130
}
126131

127132
/**
@@ -132,6 +137,10 @@ public function commit()
132137
*/
133138
private function isHierarchyKey($key)
134139
{
140+
if (!is_string($key)) {
141+
throw new InvalidArgumentException(sprintf('Key must be string.'));
142+
}
143+
135144
return substr($key, 0, 1) === self::SEPARATOR;
136145
}
137146
}

0 commit comments

Comments
 (0)