Skip to content

Commit 12bd3c2

Browse files
[Cache] Handle serialization failures for Memcached
1 parent 5556a3a commit 12bd3c2

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

src/Symfony/Component/Cache/Traits/MemcachedTrait.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ trait MemcachedTrait
2626
'persistent_id' => null,
2727
'username' => null,
2828
'password' => null,
29+
'serializer' => 'php',
2930
);
3031

3132
private $client;
@@ -186,15 +187,32 @@ public static function createConnection($servers, array $options = array())
186187
*/
187188
protected function doSave(array $values, $lifetime)
188189
{
189-
return $this->checkResultCode($this->client->setMulti($values, $lifetime));
190+
$serialized = array();
191+
$failed = array();
192+
193+
foreach ($values as $id => $value) {
194+
try {
195+
$serialized[$id] = serialize($value);
196+
} catch (\Exception $e) {
197+
$failed[] = $id;
198+
}
199+
}
200+
201+
if (!$serialized) {
202+
return $failed;
203+
}
204+
205+
return $this->checkResultCode($this->client->setMulti($serialized, $lifetime)) ? $failed : false;
190206
}
191207

192208
/**
193209
* {@inheritdoc}
194210
*/
195211
protected function doFetch(array $ids)
196212
{
197-
return $this->checkResultCode($this->client->getMulti($ids));
213+
foreach ($this->checkResultCode($this->client->getMulti($ids)) as $id => $value) {
214+
yield $id => parent::unserialize($value);
215+
}
198216
}
199217

200218
/**

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy