Пример #1
0
 /**
  * {@inheritdoc}
  */
 public function storeData($key, $data, $expiration)
 {
     if ($this->collection instanceof \MongoDB\Collection) {
         $id = self::mapKey($key);
         try {
             $this->collection->replaceOne(['_id' => $id], ['_id' => $id, 'data' => serialize($data), 'expiration' => $expiration], ['upsert' => true]);
         } catch (\MongoDB\Driver\Exception\BulkWriteException $ignored) {
             // As of right now, BulkWriteException can be thrown by replaceOne in high-throughput environments where race conditions can occur
         }
     } else {
         try {
             $this->collection->save(['_id' => self::mapKey($key), 'data' => serialize($data), 'expiration' => $expiration]);
         } catch (\MongoDuplicateKeyException $ignored) {
             // Because it's Mongo, we might have had this problem because of a cache stampede
         }
     }
     return true;
 }