public function testUncompactNoDependency() { $compact = array('foo', 'bar', 'baz', 1234); $item = Item::uncompact($compact); $this->assertEquals('foo', $item->cacheId); $this->assertEquals('bar', $item->key); $this->assertEquals('baz', $item->value); $this->assertEquals(1234, $item->timestamp); $this->assertNull($item->dependency); }
function get($cacheId, $key) { $pdo = $this->connector->pdo ?: $this->connector->connect(); $tableName = $this->getTableName($cacheId); $keyHash = $this->hashKey($key); $sql = "SELECT itemData, creationTimestamp FROM `{$tableName}` WHERE keyHash=?"; $stmt = $pdo->prepare($sql); if ($stmt->execute(array($keyHash)) === false) { throw new \UnexpectedValueException("Cache {$cacheId} get query failed: " . implode(' ', $stmt->errorInfo())); } $record = $stmt->fetch(\PDO::FETCH_ASSOC); $ret = null; if ($record) { $itemData = unserialize($record['itemData']); $itemData[Item::COMPACT_CACHE_ID] = $cacheId; $itemData[Item::COMPACT_TIMESTAMP] = $record['creationTimestamp']; $ret = Item::uncompact($itemData); } return $ret; }
function decode($data) { $itemData = @unserialize($data); if ($itemData) { return Item::uncompact($itemData); } }