Exemplo n.º 1
0
 /**
  * @param \Psr\Cache\CacheItemInterface $item
  * @return mixed
  * @throws \InvalidArgumentException
  */
 protected function driverWrite(CacheItemInterface $item)
 {
     /**
      * Check for Cross-Driver type confusion
      */
     if ($item instanceof Item) {
         try {
             $result = (array) $this->getCollection()->update(['_id' => $item->getKey()], ['$set' => [self::DRIVER_EDATE_WRAPPER_INDEX => $item->getTtl() > 0 ? new MongoDate(time() + $item->getTtl()) : new MongoDate(time()), self::DRIVER_DATA_WRAPPER_INDEX => new MongoBinData($this->encode($item->get()), MongoBinData::BYTE_ARRAY), self::DRIVER_TAGS_WRAPPER_INDEX => new MongoBinData($this->encode($item->getTags()), MongoBinData::BYTE_ARRAY)]], ['upsert' => true, 'multiple' => false]);
         } catch (MongoCursorException $e) {
             return false;
         }
         return isset($result['ok']) ? $result['ok'] == 1 : true;
     } else {
         throw new \InvalidArgumentException('Cross-Driver type confusion detected');
     }
 }