Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
a6ed3bf
Adding support for Memcached getMulti implementing the AbstractCacheP…
detain Aug 13, 2018
13f78c3
adding support for Memcached setMulti and deleteMulti calls via setMu…
detain Aug 13, 2018
26d3fed
Updates supporting both pre 3.0.0 and style getMulti calls
detain Aug 14, 2018
f2a60f7
style/formatting updates
detain Aug 14, 2018
8aef094
updates fixing the one test error
detain Aug 14, 2018
1522b63
updates fixing the one test error
detain Aug 14, 2018
1d523a6
fix
detain Aug 14, 2018
de2b98d
updates returning an Iterator from getMultiple and not using the cust…
detain Aug 14, 2018
d86f656
style conformity
detain Aug 14, 2018
ffbd85c
added setting the serializer to use php serializer and removed serial…
detain Aug 14, 2018
38bd855
minor fix
detain Aug 14, 2018
99aa20d
updates improving the ttl handling
detain Aug 14, 2018
3837822
returning a generator now from getmultple
detain Aug 14, 2018
5b24789
styling
detain Aug 14, 2018
42e10a2
styling
detain Aug 14, 2018
8330518
reverting undesired change
detain Aug 14, 2018
f229323
Merge branch 'master' of github.com:php-cache/cache
detain Apr 8, 2019
4e5593e
Merge branch 'master' of github.com:php-cache/cache
detain Aug 14, 2019
bb7b0b2
Merge branch 'master' of github.com:php-cache/cache
detain Nov 29, 2020
5f0e8e4
Merge branch 'master' of github.com:php-cache/cache
detain Jan 12, 2021
d422646
Add .whitesource configuration file
mend-bolt-for-github[bot] Jan 1, 2022
5ab7291
Merge branch 'php-cache:master' into master
detain Sep 1, 2022
ba35d78
Update composer.json keywords
detain May 7, 2026
2f1a50b
Bump shivammathur/setup-php
dependabot[bot] May 20, 2026
a9d4413
Merge pull request #1 from detain/whitesource/configure
detain May 20, 2026
c152289
Merge pull request #2 from detain/dependabot/github_actions/dot-githu…
detain May 20, 2026
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
2 changes: 1 addition & 1 deletion .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:

steps:
- name: Set up PHP
uses: shivammathur/setup-php@2.7.0
uses: shivammathur/setup-php@2.37.1
with:
php-version: 7.4
coverage: none
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:

steps:
- name: Set up PHP
uses: shivammathur/setup-php@2.7.0
uses: shivammathur/setup-php@2.37.1
with:
php-version: ${{ matrix.php }}
coverage: none
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/static.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:

steps:
- name: Set up PHP
uses: shivammathur/setup-php@2.7.0
uses: shivammathur/setup-php@2.37.1
with:
php-version: '7.4'
coverage: none
Expand All @@ -36,7 +36,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Set up PHP
uses: shivammathur/setup-php@v2
uses: shivammathur/setup-php@2.37.1
with:
php-version: '7.4'
extensions: redis, memcached, apcu
Expand Down
12 changes: 12 additions & 0 deletions .whitesource
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"scanSettings": {
"baseBranches": []
},
"checkRunSettings": {
"vulnerableCheckRunConclusionLevel": "failure",
"displayMode": "diff"
},
"issueSettings": {
"minSeverityLevel": "LOW"
}
}
18 changes: 17 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,23 @@
"type": "library",
"keywords": [
"cache",
"psr6"
"psr6",
"psr-6",
"php-cache",
"cache-adapter",
"caching",
"apcu",
"redis",
"memcached",
"mongodb",
"mysql",
"doctrine-cache",
"predis",
"file-cache",
"memcache",
"session-cache",
"serverside-cache",
"php"
],
"authors": [
{
Expand Down
114 changes: 113 additions & 1 deletion src/Adapter/Memcached/MemcachedCachePool.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Cache\Adapter\Memcached;

use Cache\Adapter\Common\AbstractCachePool;
use Cache\Adapter\Common\Exception\InvalidArgumentException;
use Cache\Adapter\Common\PhpCacheItem;
use Cache\Adapter\Common\TagSupportWithArray;
use Cache\Hierarchy\HierarchicalCachePoolTrait;
Expand Down Expand Up @@ -45,13 +46,124 @@
*/
protected function fetchObjectFromCache($key)
{
if (false === $result = unserialize($this->cache->get($this->getHierarchyKey($key)))) {
$value = $this->cache->get($this->getHierarchyKey($key));
if (false === $result = (is_array($value) ? $value : unserialize($value))) {
return [false, null, [], null];
}

return $result;
}

/**
* {@inheritdoc}
*/
public function getMultiple($keys, $default = null)
{
if (!is_array($keys)) {
if (!$keys instanceof \Traversable) {
throw new InvalidArgumentException('$keys is neither an array nor Traversable');
}
// Since we need to throw an exception if *any* key is invalid, it doesn't make sense to wrap iterators or something like that.
$keys = iterator_to_array($keys, false);
}
$items = [];
foreach ($keys as $key) {
$this->validateKey($key);
$items[] = $this->getHierarchyKey($key);
}
if (defined('\Memcached::GET_EXTENDED') === false) {
$null = null;
$results = $this->cache->getMulti($items, $null, \Memcached::GET_PRESERVE_ORDER);
} else {
$results = $this->cache->getMulti($items, \Memcached::GET_PRESERVE_ORDER);
}
/**
* @param $default
* @param $items
* @param $results
* @param $keys
*
* @return \Generator
*/
$return = function ($default, $items, $results, $keys) {

Check failure on line 88 in src/Adapter/Memcached/MemcachedCachePool.php

View workflow job for this annotation

GitHub Actions / PHPStan

PHPDoc tag @param has invalid value ($results): Unexpected token "$results", expected type at offset 74

Check failure on line 88 in src/Adapter/Memcached/MemcachedCachePool.php

View workflow job for this annotation

GitHub Actions / PHPStan

PHPDoc tag @param has invalid value ($keys): Unexpected token "$keys", expected type at offset 101

Check failure on line 88 in src/Adapter/Memcached/MemcachedCachePool.php

View workflow job for this annotation

GitHub Actions / PHPStan

PHPDoc tag @param has invalid value ($items): Unexpected token "$items", expected type at offset 49

Check failure on line 88 in src/Adapter/Memcached/MemcachedCachePool.php

View workflow job for this annotation

GitHub Actions / PHPStan

PHPDoc tag @param has invalid value ($default): Unexpected token "$default", expected type at offset 22
foreach ($keys as $idx => $key) {
$value = (false === $return[$key] = (isset($results[$items[$idx]]) ? (is_array($results[$items[$idx]]) ? $results[$items[$idx]] : unserialize($results[$items[$idx]])) : false)) ? $default : $return[$key][1];
yield $key => $value;
}
};

return $return($default, $items, $results, $keys);
}

/**
* {@inheritdoc}
*/
public function setMultiple($values, $ttl = null)
{
if (!is_array($values)) {
if (!$values instanceof \Traversable) {
throw new InvalidArgumentException('$values is neither an array nor Traversable');
}
}
$keys = [];
$arrayValues = [];
foreach ($values as $key => $value) {
if (is_int($key)) {
$key = (string) $key;
}
$this->validateKey($key);
$keys[] = $key;
$arrayValues[$key] = $value;
}
$items = $this->getItems($keys);
$itemSuccess = true;
$set = [];
foreach ($items as $key => $item) {
$item->expiresAfter($ttl);
$set[$this->getHierarchyKey($key)] = [true, $arrayValues[$key], $item->getTags(), $item->getExpirationTimestamp()];
}
if ($ttl instanceof \DateInterval) {
$ttl = $ttl->format('%s');
} elseif ($ttl instanceof \DateTimeInterface) {

Check failure on line 127 in src/Adapter/Memcached/MemcachedCachePool.php

View workflow job for this annotation

GitHub Actions / PHPStan

Instanceof between int|null and DateTimeInterface will always evaluate to false.
$ttl = $ttl->getTimestamp() - time();
}
if (is_numeric($ttl)) {
$ttl = intval($ttl);
if ($ttl <= (86400 * 30)) {
$ttl++;
}
}
$itemSuccess = $this->cache->setMulti($set, $ttl);

return $itemSuccess;
}

/**
* {@inheritdoc}
*/
public function deleteMultiple($keys)
{
if (!method_exists('\Memcached', 'deleteMulti')) {
return parent::deleteMultiple($keys);
}
if (!is_array($keys)) {
if (!$keys instanceof \Traversable) {
throw new InvalidArgumentException('$keys is neither an array nor Traversable');
}
// Since we need to throw an exception if *any* key is invalid, it doesn't make sense to wrap iterators or something like that.
$keys = iterator_to_array($keys, false);
}
$items = [];
foreach ($keys as $key) {
$this->validateKey($key);
$items[] = $this->getHierarchyKey($key);
}
$this->cache->deleteMulti($items);

return true;
//return $this->deleteItems($keys);
}

/**
* {@inheritdoc}
*/
Expand Down
Loading