Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
174 changes: 0 additions & 174 deletions src/SplitIO/Component/Cache/Item.php

This file was deleted.

11 changes: 5 additions & 6 deletions src/SplitIO/Component/Cache/Pool.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,13 @@ public function __construct(array $options = array())
* If the $key string is not a legal value a \Psr\Cache\InvalidArgumentException
* MUST be thrown.
*
* @return \SplitIO\Component\Cache\Item
* The corresponding Cache Item.
* @return string
*/
public function getItem($key)
public function get($key)
{
$this->assertValidKey($key);
Di::getLogger()->debug("Fetching item ** $key ** from cache");
return $this->adapter->getItem($key);
return $this->adapter->get($key);
}

/**
Expand All @@ -60,9 +59,9 @@ public function getItem($key)
* key is not found. However, if no keys are specified then an empty
* traversable MUST be returned instead.
*/
public function getItems(array $keys = array())
public function fetchMany(array $keys = array())
{
return $this->adapter->getItems($keys);
return $this->adapter->fetchMany($keys);
}

public function isItemOnList($key, $value)
Expand Down
2 changes: 1 addition & 1 deletion src/SplitIO/Component/Cache/SegmentCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function isInSegment($segmentName, $key)
*/
public function getChangeNumber($segmentName)
{
$since = Di::getCache()->getItem(self::getCacheKeyForSinceParameter($segmentName))->get();
$since = Di::getCache()->get(self::getCacheKeyForSinceParameter($segmentName));
// empty check for nullable value
return (empty($since)) ? -1 : $since;
}
Expand Down
12 changes: 6 additions & 6 deletions src/SplitIO/Component/Cache/SplitCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ private static function getSplitNameFromCacheKey($key)
*/
public function getChangeNumber()
{
$since = Di::getCache()->getItem(self::getCacheKeyForSinceParameter())->get();
$since = Di::getCache()->get(self::getCacheKeyForSinceParameter());
// empty check for nullable value
return (empty($since)) ? -1 : $since;
}
Expand All @@ -49,8 +49,8 @@ public function getChangeNumber()
public function getSplit($splitName)
{
$cache = Di::getCache();
$cacheItem = $cache->getItem(self::getCacheKeyForSplit($splitName));
return $cacheItem->get();
$cacheItem = $cache->get(self::getCacheKeyForSplit($splitName));
return $cacheItem;
}

/**
Expand All @@ -60,10 +60,10 @@ public function getSplit($splitName)
public function getSplits($splitNames)
{
$cache = Di::getCache();
$cacheItems = $cache->getItems(array_map('self::getCacheKeyForSplit', $splitNames));
$cacheItems = $cache->fetchMany(array_map('self::getCacheKeyForSplit', $splitNames));
$toReturn = array();
foreach ($cacheItems as $key => $value) {
$toReturn[self::getSplitNameFromCacheKey($key)] = $value->get();
$toReturn[self::getSplitNameFromCacheKey($key)] = $value;
}
return $toReturn;
}
Expand Down Expand Up @@ -100,7 +100,7 @@ public function trafficTypeExists($trafficType)
{
$cache = Di::getCache();

$count = $cache->getItem(self::getCacheKeyForTrafficType($trafficType))->get();
$count = $cache->get(self::getCacheKeyForTrafficType($trafficType));
// empty check for nullable value
return (empty($count) || $count < 1) ? false : true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ public function getKeys($pattern = '*');

/**
* @param string $key
* @return \SplitIO\Component\Cache\Item
* @return string
*/
public function getItem($key);
public function get($key);

public function getItems(array $keys);
public function fetchMany(array $keys);

/**
* @param $key
Expand Down
27 changes: 6 additions & 21 deletions src/SplitIO/Component/Cache/Storage/Adapter/PRedis.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,19 +205,11 @@ private function getRedisConfiguration($options)

/**
* @param string $key
* @return \SplitIO\Component\Cache\Item
* @return string
*/
public function getItem($key)
public function get($key)
{
$item = new Item($key);

$redisItem = $this->client->get($key);

if ($redisItem !== null) {
$item->set($redisItem);
}

return $item;
return $this->client->get($key);
}


Expand All @@ -231,24 +223,17 @@ public function getItem($key)
* If any of the keys in $keys are not a legal value a \Psr\Cache\InvalidArgumentException
* MUST be thrown.
*
* @return array|\Traversable
* A traversable collection of Cache Items keyed by the cache keys of
* each item. A Cache item will be returned for each key, even if that
* key is not found. However, if no keys are specified then an empty
* traversable MUST be returned instead.
* @return array
*/
public function getItems(array $keys = array())
public function fetchMany(array $keys = array())
{
$toReturn = array();
if (count($keys) == 0) {
return $toReturn;
}
$values = $this->client->mget($keys);
foreach ($keys as $index => $key) {
$toReturn[$key] = new Item($key);
if (!is_null($values[$index])) {
$toReturn[$key]->set($values[$index]);
}
$toReturn[$key] = $values[$index];
}
return $toReturn;
}
Expand Down
12 changes: 6 additions & 6 deletions src/SplitIO/Component/Cache/Storage/Adapter/SafeRedisWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@ public function __construct(PRedis $cacheAdapter)

/**
* @param string $key
* @return \SplitIO\Component\Cache\Item
* @return string
*/
public function getItem($key)
public function get($key)
{
try {
return $this->cacheAdapter->getItem($key);
return $this->cacheAdapter->get($key);
} catch (\Exception $e) {
Di::getLogger()->critical("An error occurred getting " . $key . " from redis.");
Di::getLogger()->critical($e->getMessage());
Di::getLogger()->critical($e->getTraceAsString());
return new Item($key);
return null;
}
}

Expand All @@ -48,10 +48,10 @@ public function getItem($key)
*
* @return array
*/
public function getItems(array $keys = array())
public function fetchMany(array $keys = array())
{
try {
return $this->cacheAdapter->getItems($keys);
return $this->cacheAdapter->fetchMany($keys);
} catch (\Exception $e) {
Di::getLogger()->critical("An error occurred getting " . json_encode($keys) . " from redis.");
Di::getLogger()->critical($e->getMessage());
Expand Down
Loading