Skip to content
Open
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
adding support for Memcached setMulti and deleteMulti calls via setMu…
…ltiple and deleteMultiple calls in the adapter
  • Loading branch information
detain committed Aug 13, 2018
commit 13f78c30d4207b6e91f130bf30467139b7ba2758
66 changes: 66 additions & 0 deletions src/Adapter/Memcached/MemcachedCachePool.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,72 @@ public function getMultiple($keys, $default = null)
return $return;;
}

/**
* {@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 = [];
if ($ttl === null) {
$expirationTimestamp = null;
} elseif ($ttl instanceof \DateTimeInterface) {
$expirationTimestamp = $ttl->getTimestamp();
} elseif ($ttl instanceof \DateInterval) {
$date = new \DateTime();
$date->add($ttl);
$expirationTimestamp = $date->getTimestamp();
} elseif (is_object($ttl)) {
$expirationTimestamp = null;
} else {
$expirationTimestamp = $ttl;
}
foreach ($items as $key => $item) {
$item->expiresAfter($ttl);
$set[$this->getHierarchyKey($key)] = serialize([true, $arrayValues[$key], $item->getTags(), $item->getExpirationTimestamp()]);
}
$itemSuccess = $this->cache->setMulti($set, $expirationTimestamp);
return $itemSuccess;
}

/**
* {@inheritdoc}
*/
public function 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