function set(Item $item) { $pdo = $this->connector->pdo ?: $this->connector->connect(); $tableName = $this->getTableName($item->cacheId); $expiryTimestamp = null; if ($item->dependency && method_exists($item->dependency, 'getExpiryTimestamp')) { $expiryTimestamp = $item->dependency->getExpiryTimestamp(); } $itemData = $item->compact(); unset($itemData[Item::COMPACT_CACHE_ID]); unset($itemData[Item::COMPACT_TIMESTAMP]); $sql = "\n REPLACE INTO `{$tableName}` (\n cacheKey, keyHash, itemData, creationTimestamp, expiryTimestamp\n )\n VALUES(?, ?, ?, ?, ?)\n "; $stmt = $pdo->prepare($sql); $keyHash = $this->hashKey($item->key); $params = [$item->key, $keyHash, serialize($itemData), $item->timestamp, $expiryTimestamp]; if ($stmt->execute($params) === false) { throw new \UnexpectedValueException("Cache {$cacheId} set query failed: " . implode(' ', $stmt->errorInfo())); } }
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 decode($data) { $itemData = @unserialize($data); if ($itemData) { return Item::uncompact($itemData); } }