Path: blob/master/src/applications/cache/PhabricatorKeyValueSerializingCacheProxy.php
12242 views
<?php12/**3* Proxies another cache and serializes values.4*5* This allows more complex data to be stored in a cache which can only store6* strings.7*/8final class PhabricatorKeyValueSerializingCacheProxy9extends PhutilKeyValueCacheProxy {1011public function getKeys(array $keys) {12$results = parent::getKeys($keys);1314$reads = array();15foreach ($results as $key => $result) {16$structure = @unserialize($result);1718// The unserialize() function returns false when unserializing a19// literal `false`, and also when it fails. If we get a literal20// `false`, test if the serialized form is the same as the21// serialization of `false` and miss the cache otherwise.22if ($structure === false) {23static $serialized_false;24if ($serialized_false === null) {25$serialized_false = serialize(false);26}27if ($result !== $serialized_false) {28continue;29}30}3132$reads[$key] = $structure;33}3435return $reads;36}3738public function setKeys(array $keys, $ttl = null) {39$writes = array();40foreach ($keys as $key => $value) {41if (is_object($value)) {42throw new Exception(43pht(44'Serializing cache can not write objects (for key "%s")!',45$key));46}47$writes[$key] = serialize($value);48}4950return parent::setKeys($writes, $ttl);51}525354}555657