Created
December 6, 2017 00:55
-
-
Save Geolim4/25f735b163fd9874d86bc9223dbd20a4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Index: src/phpFastCache/Drivers/Mongodb/Driver.php | |
IDEA additional info: | |
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP | |
<+>UTF-8 | |
=================================================================== | |
--- src/phpFastCache/Drivers/Mongodb/Driver.php (revision aa05addaa6fa00378a0bc87e36aecca8436491a0) | |
+++ src/phpFastCache/Drivers/Mongodb/Driver.php (revision ) | |
@@ -87,15 +87,22 @@ | |
*/ | |
if ($item instanceof Item) { | |
try { | |
- $result = (array)$this->getCollection()->updateOne( | |
- ['_id' => $item->getEncodedKey()], | |
- [ | |
- '$set' => [ | |
- self::DRIVER_DATA_WRAPPER_INDEX => new Binary($this->encode($item->get()), Binary::TYPE_GENERIC), | |
- self::DRIVER_TAGS_WRAPPER_INDEX => new Binary($this->encode($item->getTags()), Binary::TYPE_GENERIC), | |
- self::DRIVER_EDATE_WRAPPER_INDEX => ($item->getTtl() > 0 ? new UTCDateTime((time() + $item->getTtl()) * 1000) : new UTCDateTime(time() * 1000)), | |
- ], | |
- ], | |
+ $set = [ | |
+ self::DRIVER_DATA_WRAPPER_INDEX => new Binary($this->encode($item->get()), Binary::TYPE_GENERIC), | |
+ self::DRIVER_TAGS_WRAPPER_INDEX => new Binary($this->encode($item->getTags()), Binary::TYPE_GENERIC), | |
+ self::DRIVER_EDATE_WRAPPER_INDEX => ($item->getTtl() > 0 ? new UTCDateTime((time() + $item->getTtl()) * 1000) : new UTCDateTime(time() * 1000)), | |
+ ]; | |
+ | |
+ if(!empty($this->config[ 'itemDetailedDate' ])){ | |
+ $set += [ | |
+ self::DRIVER_MDATE_WRAPPER_INDEX => ($item->getModificationDate() ? new UTCDateTime(($item->getModificationDate()->getTimestamp()) * 1000) : new UTCDateTime(time() * 1000)), | |
+ self::DRIVER_CDATE_WRAPPER_INDEX => ($item->getCreationDate() ? new UTCDateTime(($item->getCreationDate()->getTimestamp()) * 1000) : new UTCDateTime(time() * 1000)), | |
+ ]; | |
+ } | |
+ | |
+ $result = (array)$this->getCollection()->updateOne( | |
+ ['_id' => $item->getEncodedKey()], | |
+ ['$set' => $set], | |
['upsert' => true, 'multiple' => false] | |
); | |
} catch (MongoDBException $e) { | |
@@ -117,11 +124,20 @@ | |
$document = $this->getCollection()->findOne(['_id' => $item->getEncodedKey()]); | |
if ($document) { | |
- return [ | |
+ $return = [ | |
self::DRIVER_DATA_WRAPPER_INDEX => $this->decode($document[ self::DRIVER_DATA_WRAPPER_INDEX ]->getData()), | |
self::DRIVER_TAGS_WRAPPER_INDEX => $this->decode($document[ self::DRIVER_TAGS_WRAPPER_INDEX ]->getData()), | |
self::DRIVER_EDATE_WRAPPER_INDEX => (new \DateTime())->setTimestamp($document[ self::DRIVER_EDATE_WRAPPER_INDEX ]->toDateTime()->getTimestamp()), | |
]; | |
+ | |
+ if(!empty($this->config[ 'itemDetailedDate' ])){ | |
+ $return += [ | |
+ self::DRIVER_MDATE_WRAPPER_INDEX => (new \DateTime())->setTimestamp($document[ self::DRIVER_MDATE_WRAPPER_INDEX ]->toDateTime()->getTimestamp()), | |
+ self::DRIVER_CDATE_WRAPPER_INDEX => (new \DateTime())->setTimestamp($document[ self::DRIVER_CDATE_WRAPPER_INDEX ]->toDateTime()->getTimestamp()), | |
+ ]; | |
+ } | |
+ | |
+ return $return; | |
} else { | |
return null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment