Skip to content

Commit

Permalink
Add getAll method.
Browse files Browse the repository at this point in the history
  • Loading branch information
terrylinooo committed Oct 28, 2020
1 parent e4a8c5b commit 70ac4ac
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 26 deletions.
3 changes: 1 addition & 2 deletions src/SimpleCache/Driver/Apc.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,8 @@ protected function getAll(): array
$list = [];

foreach (new APCIterator('/^sc_/') as $item) {
$key = str_replace('sc_', '', $item['key']);
$key = str_replace('sc_', '', $item['key']);
$value = unserialize($item['value']);

$list[$key] = $value;
}

Expand Down
3 changes: 1 addition & 2 deletions src/SimpleCache/Driver/Apcu.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,8 @@ protected function getAll(): array
$list = [];

foreach (new APCUIterator('/^sc_/') as $item) {
$key = str_replace('sc_', '', $item['key']);
$key = str_replace('sc_', '', $item['key']);
$value = unserialize($item['value']);

$list[$key] = $value;
}

Expand Down
41 changes: 20 additions & 21 deletions src/SimpleCache/Driver/Mongo.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,26 @@ protected function doHas(string $key): bool
return true;
}

/**
* Fetch all cache items.
*
* @return array
*/
protected function getAll(): array
{
$list = [];

$query = new MongoQuery([]);
$cursor = $this->mongo->executeQuery($this->getCollectionName(), $query);

foreach ($cursor as $document) {
$key = str_replace('sc_', '', $document->_id);
$value = unserialize($document->content);
$list[$key] = $value;
}
return $list;
}

/**
* Perform the write operation and return the result.
*
Expand Down Expand Up @@ -311,25 +331,4 @@ private function getCollectionName(): string
{
return $this->dbname . '.' . $this->collection;
}

/**
* Fetch all cache items.
*
* @return array
*/
protected function getAll(): array
{
$list = [];

$query = new MongoQuery([]);
$cursor = $this->mongo->executeQuery($this->getCollectionName(), $query);

foreach ($cursor as $document) {
$key = str_replace('sc_', '', $document->_id);
$value = unserialize($document->content);

$list[$key] = $value;
}
return $list;
}
}
22 changes: 21 additions & 1 deletion src/SimpleCache/Driver/Redis.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,26 @@ protected function doHas(string $key): bool
// @codeCoverageIgnoreEnd
}

/**
* Fetch all cache items.
*
* @return array
*/
protected function getAll(): array
{
$list = [];
$keys = $this->redis->keys('sc:*');

if (!empty($keys)) {
foreach ($keys as $key) {
$value = $this->doGet($key);
$key = str_replace('sc_', '', $key);
$list[$key] = $value;
}
}
return $list;
}

/**
* Get the key name of a cache.
*
Expand All @@ -237,7 +257,7 @@ protected function doHas(string $key): bool
*/
private function getKeyName(string $key): string
{
return 'sc:' . md5($key);
return 'sc:' . $key;
}
}

18 changes: 18 additions & 0 deletions src/SimpleCache/Driver/Wincache.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,5 +134,23 @@ protected function doHas(string $key): bool
{
return wincache_ucache_exists($key);
}

/**
* Fetch all cache items.
*
* @return array
*/
protected function getAll(): array
{
$list = [];
$info = wincache_ucache_info();

foreach ($info['ucache_entries'] as $item) {
$key = $item['key_name'];
$value = $this->doGet($key);
$list[$key] = $value;
}
return $list;
}
}

0 comments on commit 70ac4ac

Please sign in to comment.