public function serialize($prefix, array $data, $minutes, array $tags) { $seconds = TimeTools::getTtlInSeconds($minutes); $tags = $this->tagVersions->getActualVersionsFor($tags); $data = ArrayTools::addPrefixToArrayKeys($prefix, $data); $data = array_map(function ($value) use($seconds, $tags) { return (string) CacheItem::encode($this->isSimpleType($value) ? $value : $this->coderManager->encode($value), $seconds, $tags); }, $data); return $data; }
public function testEncodeDecode() { $length = rand(0, 100); $value = []; for ($i = 0; $i < $length; $i++) { if (rand(0, 1)) { $value[] = Str::random(); } else { $value[count($value) - 1] = Str::random(); } } $ttl = rand(0, 100000000); $tags = ['Tag1', 'Tag2']; $now = time(); $encoded = (string) CacheItem::encode($value, $ttl, $tags, $now); $decoded = CacheItem::decode($encoded); $this->assertEquals($value, $decoded->getValue()); $this->assertEquals($ttl + $now, $decoded->getExpires()); $this->assertEquals($tags, $decoded->getTags()); }