Skip to content

Commit ddcb283

Browse files
authored
Merge pull request #179 from splitio/task/removeItem
Task/remove item
2 parents f85782e + c436e33 commit ddcb283

File tree

11 files changed

+53
-243
lines changed

11 files changed

+53
-243
lines changed

src/SplitIO/Component/Cache/Item.php

Lines changed: 0 additions & 174 deletions
This file was deleted.

src/SplitIO/Component/Cache/Pool.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,13 @@ public function __construct(array $options = array())
3434
* If the $key string is not a legal value a \Psr\Cache\InvalidArgumentException
3535
* MUST be thrown.
3636
*
37-
* @return \SplitIO\Component\Cache\Item
38-
* The corresponding Cache Item.
37+
* @return string
3938
*/
40-
public function getItem($key)
39+
public function get($key)
4140
{
4241
$this->assertValidKey($key);
4342
Di::getLogger()->debug("Fetching item ** $key ** from cache");
44-
return $this->adapter->getItem($key);
43+
return $this->adapter->get($key);
4544
}
4645

4746
/**
@@ -60,9 +59,9 @@ public function getItem($key)
6059
* key is not found. However, if no keys are specified then an empty
6160
* traversable MUST be returned instead.
6261
*/
63-
public function getItems(array $keys = array())
62+
public function fetchMany(array $keys = array())
6463
{
65-
return $this->adapter->getItems($keys);
64+
return $this->adapter->fetchMany($keys);
6665
}
6766

6867
public function isItemOnList($key, $value)

src/SplitIO/Component/Cache/SegmentCache.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function isInSegment($segmentName, $key)
3636
*/
3737
public function getChangeNumber($segmentName)
3838
{
39-
$since = Di::getCache()->getItem(self::getCacheKeyForSinceParameter($segmentName))->get();
39+
$since = Di::getCache()->get(self::getCacheKeyForSinceParameter($segmentName));
4040
// empty check for nullable value
4141
return (empty($since)) ? -1 : $since;
4242
}

src/SplitIO/Component/Cache/SplitCache.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ private static function getSplitNameFromCacheKey($key)
3737
*/
3838
public function getChangeNumber()
3939
{
40-
$since = Di::getCache()->getItem(self::getCacheKeyForSinceParameter())->get();
40+
$since = Di::getCache()->get(self::getCacheKeyForSinceParameter());
4141
// empty check for nullable value
4242
return (empty($since)) ? -1 : $since;
4343
}
@@ -49,8 +49,8 @@ public function getChangeNumber()
4949
public function getSplit($splitName)
5050
{
5151
$cache = Di::getCache();
52-
$cacheItem = $cache->getItem(self::getCacheKeyForSplit($splitName));
53-
return $cacheItem->get();
52+
$cacheItem = $cache->get(self::getCacheKeyForSplit($splitName));
53+
return $cacheItem;
5454
}
5555

5656
/**
@@ -60,10 +60,10 @@ public function getSplit($splitName)
6060
public function getSplits($splitNames)
6161
{
6262
$cache = Di::getCache();
63-
$cacheItems = $cache->getItems(array_map('self::getCacheKeyForSplit', $splitNames));
63+
$cacheItems = $cache->fetchMany(array_map('self::getCacheKeyForSplit', $splitNames));
6464
$toReturn = array();
6565
foreach ($cacheItems as $key => $value) {
66-
$toReturn[self::getSplitNameFromCacheKey($key)] = $value->get();
66+
$toReturn[self::getSplitNameFromCacheKey($key)] = $value;
6767
}
6868
return $toReturn;
6969
}
@@ -100,7 +100,7 @@ public function trafficTypeExists($trafficType)
100100
{
101101
$cache = Di::getCache();
102102

103-
$count = $cache->getItem(self::getCacheKeyForTrafficType($trafficType))->get();
103+
$count = $cache->get(self::getCacheKeyForTrafficType($trafficType));
104104
// empty check for nullable value
105105
return (empty($count) || $count < 1) ? false : true;
106106
}

src/SplitIO/Component/Cache/Storage/Adapter/CacheStorageAdapterInterface.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ public function getKeys($pattern = '*');
1414

1515
/**
1616
* @param string $key
17-
* @return \SplitIO\Component\Cache\Item
17+
* @return string
1818
*/
19-
public function getItem($key);
19+
public function get($key);
2020

21-
public function getItems(array $keys);
21+
public function fetchMany(array $keys);
2222

2323
/**
2424
* @param $key

src/SplitIO/Component/Cache/Storage/Adapter/PRedis.php

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -205,19 +205,11 @@ private function getRedisConfiguration($options)
205205

206206
/**
207207
* @param string $key
208-
* @return \SplitIO\Component\Cache\Item
208+
* @return string
209209
*/
210-
public function getItem($key)
210+
public function get($key)
211211
{
212-
$item = new Item($key);
213-
214-
$redisItem = $this->client->get($key);
215-
216-
if ($redisItem !== null) {
217-
$item->set($redisItem);
218-
}
219-
220-
return $item;
212+
return $this->client->get($key);
221213
}
222214

223215

@@ -231,24 +223,17 @@ public function getItem($key)
231223
* If any of the keys in $keys are not a legal value a \Psr\Cache\InvalidArgumentException
232224
* MUST be thrown.
233225
*
234-
* @return array|\Traversable
235-
* A traversable collection of Cache Items keyed by the cache keys of
236-
* each item. A Cache item will be returned for each key, even if that
237-
* key is not found. However, if no keys are specified then an empty
238-
* traversable MUST be returned instead.
226+
* @return array
239227
*/
240-
public function getItems(array $keys = array())
228+
public function fetchMany(array $keys = array())
241229
{
242230
$toReturn = array();
243231
if (count($keys) == 0) {
244232
return $toReturn;
245233
}
246234
$values = $this->client->mget($keys);
247235
foreach ($keys as $index => $key) {
248-
$toReturn[$key] = new Item($key);
249-
if (!is_null($values[$index])) {
250-
$toReturn[$key]->set($values[$index]);
251-
}
236+
$toReturn[$key] = $values[$index];
252237
}
253238
return $toReturn;
254239
}

src/SplitIO/Component/Cache/Storage/Adapter/SafeRedisWrapper.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,17 @@ public function __construct(PRedis $cacheAdapter)
2525

2626
/**
2727
* @param string $key
28-
* @return \SplitIO\Component\Cache\Item
28+
* @return string
2929
*/
30-
public function getItem($key)
30+
public function get($key)
3131
{
3232
try {
33-
return $this->cacheAdapter->getItem($key);
33+
return $this->cacheAdapter->get($key);
3434
} catch (\Exception $e) {
3535
Di::getLogger()->critical("An error occurred getting " . $key . " from redis.");
3636
Di::getLogger()->critical($e->getMessage());
3737
Di::getLogger()->critical($e->getTraceAsString());
38-
return new Item($key);
38+
return null;
3939
}
4040
}
4141

@@ -48,10 +48,10 @@ public function getItem($key)
4848
*
4949
* @return array
5050
*/
51-
public function getItems(array $keys = array())
51+
public function fetchMany(array $keys = array())
5252
{
5353
try {
54-
return $this->cacheAdapter->getItems($keys);
54+
return $this->cacheAdapter->fetchMany($keys);
5555
} catch (\Exception $e) {
5656
Di::getLogger()->critical("An error occurred getting " . json_encode($keys) . " from redis.");
5757
Di::getLogger()->critical($e->getMessage());

0 commit comments

Comments
 (0)