Skip to content

Commit 815673b

Browse files
authored
Merge pull request #178 from splitio/task/cleanPool
Task/clean pool
2 parents 97765c1 + 7ffc5e4 commit 815673b

File tree

7 files changed

+25
-441
lines changed

7 files changed

+25
-441
lines changed

src/SplitIO/Component/Cache/Pool.php

Lines changed: 0 additions & 175 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ class Pool extends CacheKeyTrait
1010
/** @var null|\SplitIO\Component\Cache\Storage\Adapter\CacheStorageAdapterInterface */
1111
private $adapter = null;
1212

13-
/** @var array */
14-
private $deferred = array();
15-
1613
/**
1714
* @param array $options
1815
*/
@@ -68,188 +65,16 @@ public function getItems(array $keys = array())
6865
return $this->adapter->getItems($keys);
6966
}
7067

71-
/**
72-
* Confirms if the cache contains specified cache item.
73-
*
74-
* Note: This method MAY avoid retrieving the cached value for performance reasons.
75-
* This could result in a race condition with CacheItemInterface::get(). To avoid
76-
* such situation use CacheItemInterface::isHit() instead.
77-
*
78-
* @param string $key
79-
* The key for which to check existence.
80-
*
81-
* @throws \InvalidArgumentException
82-
* If the $key string is not a legal value a \Psr\Cache\InvalidArgumentException
83-
* MUST be thrown.
84-
*
85-
* @return bool
86-
* True if item exists in the cache, false otherwise.
87-
*/
88-
public function hasItem($key)
89-
{
90-
$this->assertValidKey($key);
91-
92-
$item = $this->getItem($key);
93-
return $item->isHit();
94-
}
95-
96-
/**
97-
* Deletes all items in the pool.
98-
*
99-
* @return bool
100-
* True if the pool was successfully cleared. False if there was an error.
101-
*/
102-
public function clear()
103-
{
104-
return $this->adapter->clear();
105-
}
106-
107-
/**
108-
* Removes the item from the pool.
109-
*
110-
* @param string $key
111-
* The key for which to delete
112-
*
113-
* @throws \InvalidArgumentException
114-
* If the $key string is not a legal value a \Psr\Cache\InvalidArgumentException
115-
* MUST be thrown.
116-
*
117-
* @return bool
118-
* True if the item was successfully removed. False if there was an error.
119-
*/
120-
public function deleteItem($key)
121-
{
122-
$this->assertValidKey($key);
123-
124-
return $this->adapter->deleteItem($key);
125-
}
126-
127-
/**
128-
* Removes multiple items from the pool.
129-
*
130-
* @param array $keys
131-
* An array of keys that should be removed from the pool.
132-
133-
* @throws \InvalidArgumentException
134-
* If any of the keys in $keys are not a legal value a \Psr\Cache\InvalidArgumentException
135-
* MUST be thrown.
136-
*
137-
* @return bool
138-
* True if the items were successfully removed. False if there was an error.
139-
*/
140-
public function deleteItems(array $keys)
141-
{
142-
foreach ($keys as $key) {
143-
$this->assertValidKey($key);
144-
}
145-
146-
return $this->adapter->deleteItems($keys);
147-
}
148-
149-
/**
150-
* Persists a cache item immediately.
151-
*
152-
* @param \SplitIO\Component\Cache\Item $item
153-
* The cache item to save.
154-
*
155-
* @return bool
156-
* True if the item was successfully persisted. False if there was an error.
157-
*/
158-
public function save(Item $item)
159-
{
160-
$key = $item->getKey();
161-
$value = $item->get();
162-
163-
//PSR-6 CacheItemInterface doesn't define a method to get the item expiration value.
164-
$expiration = (method_exists($item, 'getExpiration')) ? $item->getExpiration() : 0;
165-
166-
if ($this->adapter->save($key, $value, $expiration)) {
167-
Di::getLogger()->debug("Saving cache item: $key - $value - $expiration");
168-
return true;
169-
}
170-
171-
return false;
172-
}
173-
174-
/**
175-
* Sets a cache item to be persisted later.
176-
*
177-
* @param \SplitIO\Component\Cache\Item $item
178-
* The cache item to save.
179-
*
180-
* @return bool
181-
* False if the item could not be queued or if a commit was attempted and failed. True otherwise.
182-
*/
183-
public function saveDeferred(Item $item)
184-
{
185-
$this->deferred[] = $item;
186-
return true;
187-
}
188-
189-
/**
190-
* Persists any deferred cache items.
191-
*
192-
* @return bool
193-
* True if all not-yet-saved items were successfully saved or there were none. False otherwise.
194-
*/
195-
public function commit()
196-
{
197-
$success = true;
198-
199-
foreach ($this->deferred as $item) {
200-
if (! $this->save($item)) {
201-
$success = false;
202-
}
203-
}
204-
205-
if ($success) {
206-
$this->deferred = array();
207-
}
208-
209-
return $success;
210-
}
211-
212-
213-
public function saveItemOnList($key, $value)
214-
{
215-
return $this->adapter->addItemList($key, $value);
216-
}
217-
218-
public function removeItemOnList($key, $value)
219-
{
220-
return $this->adapter->removeItemList($key, $value);
221-
}
222-
22368
public function isItemOnList($key, $value)
22469
{
22570
return $this->adapter->isOnList($key, $value);
22671
}
22772

228-
public function getItemsOnList($key)
229-
{
230-
return $this->adapter->getListItems($key);
231-
}
232-
233-
public function getItemsRandomlyOnList($key, $count)
234-
{
235-
return $this->adapter->getListItemsRandomly($key, $count);
236-
}
237-
23873
public function getKeys($pattern = '*')
23974
{
24075
return $this->adapter->getKeys($pattern);
24176
}
24277

243-
public function incrementKey($key)
244-
{
245-
return $this->adapter->incrementKey($key);
246-
}
247-
248-
public function getSet($key, $value)
249-
{
250-
return $this->adapter->getSet($key, $value);
251-
}
252-
25378
public function rightPushInList($queue, $item)
25479
{
25580
return $this->adapter->rightPushQueue($queue, $item);

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,6 @@ public function getItems(array $keys);
2727
*/
2828
public function isOnList($key, $value);
2929

30-
/**
31-
* @param $key
32-
* @return mixed
33-
*/
34-
public function getListItems($key);
35-
3630
/**
3731
* @param $queueName
3832
* @param $item

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

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -260,15 +260,6 @@ public function isOnList($key, $value)
260260
return $this->client->sIsMember($key, $value);
261261
}
262262

263-
/**
264-
* @param $key
265-
* @return mixed
266-
*/
267-
public function getListItems($key)
268-
{
269-
return $this->client->sMembers($key);
270-
}
271-
272263
public function getKeys($pattern = '*')
273264
{
274265
$prefix = null;
@@ -324,54 +315,4 @@ public function expireKey($key, $ttl)
324315
{
325316
return $this->client->expire($key, $ttl);
326317
}
327-
328-
/**
329-
* @param $key
330-
* @param $value
331-
* @param int|null $expiration
332-
* @return bool
333-
*/
334-
public function save($key, $value, $expiration = null)
335-
{
336-
return $this->client->set($key, $value);
337-
}
338-
339-
/**
340-
* Adds a values to the set value stored at key.
341-
* If this value is already in the set, FALSE is returned.
342-
*
343-
* @param $key
344-
* @param $value
345-
* @return boolean
346-
*/
347-
public function addItemList($key, $value)
348-
{
349-
return $this->client->sAdd($key, $value);
350-
}
351-
352-
/**
353-
* @param string $key
354-
* @param mixed $value
355-
* @param int|null $expiration
356-
* @return bool
357-
*/
358-
public function addItem($key, $value, $expiration = null)
359-
{
360-
return $this->save($key, $value, $expiration);
361-
}
362-
363-
/**
364-
* @param $key
365-
* @return bool
366-
*/
367-
public function deleteItem($key)
368-
{
369-
$return = $this->client->del($key);
370-
371-
if ($return > 0) {
372-
return true;
373-
}
374-
375-
return false;
376-
}
377318
}

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

Lines changed: 0 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -77,22 +77,6 @@ public function isOnList($key, $value)
7777
}
7878
}
7979

80-
/**
81-
* @param $key
82-
* @return mixed
83-
*/
84-
public function getListItems($key)
85-
{
86-
try {
87-
return $this->cacheAdapter->getListItems($key);
88-
} catch (\Exception $e) {
89-
Di::getLogger()->critical("An error occurred getting " . $key);
90-
Di::getLogger()->critical($e->getMessage());
91-
Di::getLogger()->critical($e->getTraceAsString());
92-
return null;
93-
}
94-
}
95-
9680
/**
9781
* @param $pattern
9882
* @return mixed|null
@@ -142,76 +126,4 @@ public function expireKey($key, $ttl)
142126
return false;
143127
}
144128
}
145-
146-
/**
147-
* @param $key
148-
* @param $value
149-
* @param int|null $expiration
150-
* @return bool
151-
*/
152-
public function save($key, $value, $expiration = null)
153-
{
154-
try {
155-
return $this->cacheAdapter->save($key, $value, $expiration);
156-
} catch (\Exception $e) {
157-
Di::getLogger()->critical("An error occurred setting " . $key);
158-
Di::getLogger()->critical($e->getMessage());
159-
Di::getLogger()->critical($e->getTraceAsString());
160-
return false;
161-
}
162-
}
163-
164-
/**
165-
* Adds a values to the set value stored at key.
166-
* If this value is already in the set, FALSE is returned.
167-
*
168-
* @param $key
169-
* @param $value
170-
* @return boolean
171-
*/
172-
public function addItemList($key, $value)
173-
{
174-
try {
175-
return $this->cacheAdapter->addItemList($key, $value);
176-
} catch (\Exception $e) {
177-
Di::getLogger()->critical("An error occurred adding element into " . $key);
178-
Di::getLogger()->critical($e->getMessage());
179-
Di::getLogger()->critical($e->getTraceAsString());
180-
return false;
181-
}
182-
}
183-
184-
/**
185-
* @param string $key
186-
* @param mixed $value
187-
* @param int|null $expiration
188-
* @return bool
189-
*/
190-
public function addItem($key, $value, $expiration = null)
191-
{
192-
try {
193-
return $this->cacheAdapter->addItem($key, $value);
194-
} catch (\Exception $e) {
195-
Di::getLogger()->critical("An error occurred adding element into " . $key);
196-
Di::getLogger()->critical($e->getMessage());
197-
Di::getLogger()->critical($e->getTraceAsString());
198-
return false;
199-
}
200-
}
201-
202-
/**
203-
* @param $key
204-
* @return bool
205-
*/
206-
public function deleteItem($key)
207-
{
208-
try {
209-
return $this->cacheAdapter->deleteItem($key);
210-
} catch (\Exception $e) {
211-
Di::getLogger()->critical("An error occurred removing " . $key);
212-
Di::getLogger()->critical($e->getMessage());
213-
Di::getLogger()->critical($e->getTraceAsString());
214-
return false;
215-
}
216-
}
217129
}

0 commit comments

Comments
 (0)