@@ 75-101 (lines=27) @@ | ||
72 | * @return mixed |
|
73 | * @throws \InvalidArgumentException |
|
74 | */ |
|
75 | protected function driverWrite(CacheItemInterface $item) |
|
76 | { |
|
77 | /** |
|
78 | * Check for Cross-Driver type confusion |
|
79 | */ |
|
80 | if ($item instanceof Item) { |
|
81 | try { |
|
82 | $result = (array) $this->getCollection()->update( |
|
83 | ['_id' => $item->getKey()], |
|
84 | [ |
|
85 | '$set' => [ |
|
86 | self::DRIVER_TIME_WRAPPER_INDEX => ($item->getTtl() > 0 ? new MongoDate(time() + $item->getTtl()) : new MongoDate(time())), |
|
87 | self::DRIVER_DATA_WRAPPER_INDEX => new MongoBinData($this->encode($item->get()), MongoBinData::BYTE_ARRAY), |
|
88 | self::DRIVER_TAGS_WRAPPER_INDEX => new MongoBinData($this->encode($item->getTags()), MongoBinData::BYTE_ARRAY), |
|
89 | ], |
|
90 | ], |
|
91 | ['upsert' => true, 'multiple' => false] |
|
92 | ); |
|
93 | } catch (MongoCursorException $e) { |
|
94 | return false; |
|
95 | } |
|
96 | ||
97 | return isset($result[ 'ok' ]) ? $result[ 'ok' ] == 1 : true; |
|
98 | } else { |
|
99 | throw new \InvalidArgumentException('Cross-Driver type confusion detected'); |
|
100 | } |
|
101 | } |
|
102 | ||
103 | /** |
|
104 | * @param \Psr\Cache\CacheItemInterface $item |
@@ 83-109 (lines=27) @@ | ||
80 | * @return mixed |
|
81 | * @throws \InvalidArgumentException |
|
82 | */ |
|
83 | protected function driverWrite(CacheItemInterface $item) |
|
84 | { |
|
85 | /** |
|
86 | * Check for Cross-Driver type confusion |
|
87 | */ |
|
88 | if ($item instanceof Item) { |
|
89 | try { |
|
90 | $result = (array) $this->getCollection()->updateMany( |
|
91 | ['_id' => $item->getKey()], |
|
92 | [ |
|
93 | '$set' => [ |
|
94 | self::DRIVER_TIME_WRAPPER_INDEX => ($item->getTtl() > 0 ? new UTCDateTime((time() + $item->getTtl()) * 1000) : new UTCDateTime(time()*1000)), |
|
95 | self::DRIVER_DATA_WRAPPER_INDEX => new Binary($this->encode($item->get()), Binary::TYPE_GENERIC), |
|
96 | self::DRIVER_TAGS_WRAPPER_INDEX => new Binary($this->encode($item->getTags()), Binary::TYPE_GENERIC), |
|
97 | ], |
|
98 | ], |
|
99 | ['upsert' => true, 'multiple' => false] |
|
100 | ); |
|
101 | } catch (MongoCursorException $e) { |
|
102 | return false; |
|
103 | } |
|
104 | ||
105 | return isset($result[ 'ok' ]) ? $result[ 'ok' ] == 1 : true; |
|
106 | } else { |
|
107 | throw new \InvalidArgumentException('Cross-Driver type confusion detected'); |
|
108 | } |
|
109 | } |
|
110 | ||
111 | /** |
|
112 | * @param \Psr\Cache\CacheItemInterface $item |