Example #1
0
 public function testCompactWithDependency()
 {
     $dep = new Dependency\Permanent();
     $item = new Item('foo', 'bar', 'baz', $dep);
     $compact = $item->compact();
     $this->assertEquals(array('foo', 'bar', 'baz', $item->timestamp, $dep), $compact);
 }
Example #2
0
 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()));
     }
 }