/** * @param MCacheItem $item * @return bool */ public function addItem(MCacheItem $item) { $inserted = new \DateTime('now'); $endValidation = new \DateTime('now'); $endValidation = $endValidation->add(new \DateInterval(sprintf('PT%dS', $item->getTtl()))); $array = ItemTransformer::toArray($item); $array['end_validation'] = $endValidation->format(self::FILE_DATE_FORMAT); $array['inserted'] = $inserted->format(self::FILE_DATE_FORMAT); $json = json_encode($array); $filePath = $this->getBackupFilePath($item->getKey()); if (file_exists($filePath)) { unlink($this->getBackupFilePath($item->getKey())); } return file_put_contents($filePath, $json) !== false; }
/** * @param MCacheItem $item * @return bool */ public function addItem(MCacheItem $item) { $i = 0; $stmt = $this->pdoConnection->prepare(sprintf(self::$UPSERT, $this->tableName)); $stmt->bindParam(++$i, $item->getKey(), \PDO::PARAM_STR); $stmt->bindParam(++$i, $item->getValue(), \PDO::PARAM_STR); $stmt->bindParam(++$i, $item->getTtl(), \PDO::PARAM_INT); $stmt->bindParam(++$i, $item->getTtl(), \PDO::PARAM_INT); $stmt->bindParam(++$i, $item->getValue(), \PDO::PARAM_STR); $stmt->bindParam(++$i, $item->getTtl(), \PDO::PARAM_INT); $stmt->bindParam(++$i, $item->getTtl(), \PDO::PARAM_INT); return $stmt->execute(); }
/** * @param MCacheItem $item * @return array */ public static function toArray(MCacheItem $item) { return array('key' => $item->getKey(), 'value' => $item->getValue(), 'ttl' => $item->getTtl()); }