/** * * @param string $fileName * @param string $contents * * @return int */ public function write(\Fwk\Cache\CacheEntry $entry) { $fileInfos = implode(DIRECTORY_SEPARATOR, array($this->cacheDirectory, md5('cacheKey:' . $entry->getKey()) . '.cache')); $fileContents = implode(DIRECTORY_SEPARATOR, array($this->cacheDirectory, md5('cacheKey:' . $entry->getKey()))); $entry->setSerializer($this->serializer); $serialized = $entry->getSerializedContents(); file_put_contents($fileInfos, $this->serializer->serialize($entry)); file_put_contents($fileContents, $serialized); return true; }
/** * * @param string $fileName * @param string $contents * * @return int */ public function write(\Fwk\Cache\CacheEntry $entry) { if ($this->exists($entry->getKey())) { $this->delete($entry->getKey()); } $maxAge = $entry->getMaxAge(); if (is_object($maxAge)) { $maxAge = $this->serializer->serialize($maxAge); } $query = "INSERT INTO %s VALUES (%s,%s,%s,%s)"; $stmt = $this->pdo->exec(sprintf($query, $this->options['table.infos'], $this->pdo->quote($entry->getKey()), $this->pdo->quote($entry->getCreatedOn()), $this->pdo->quote($maxAge), $this->pdo->quote(implode(self::TAGS_SEPARATOR, $entry->getTags())))); $entry->setSerializer($this->serializer); $query = "INSERT INTO %s VALUES (%s, %s)"; $stmt = $this->pdo->exec(sprintf($query, $this->options['table.entries'], $this->pdo->quote($entry->getKey()), $this->pdo->quote($entry->getSerializedContents()))); return true; }