collection = $collection->withOptions(['typeMap' => null]); $this->database = new Database($collection->getManager(), $collection->getDatabaseName()); } /** * {@inheritdoc} */ protected function doFetch($id) { $document = $this->collection->findOne(['_id' => $id], [MongoDBCache::DATA_FIELD, MongoDBCache::EXPIRATION_FIELD]); if ($document === null) { return false; } if ($this->isExpired($document)) { $this->createExpirationIndex(); $this->doDelete($id); return false; } return unserialize($document[MongoDBCache::DATA_FIELD]->getData()); } /** * {@inheritdoc} */ protected function doContains($id) { $document = $this->collection->findOne(['_id' => $id], [MongoDBCache::EXPIRATION_FIELD]); if ($document === null) { return false; } if ($this->isExpired($document)) { $this->createExpirationIndex(); $this->doDelete($id); return false; } return true; } /** * {@inheritdoc} */ protected function doSave($id, $data, $lifeTime = 0) { try { $this->collection->updateOne( ['_id' => $id], [ '$set' => [ MongoDBCache::EXPIRATION_FIELD => ($lifeTime > 0 ? new UTCDateTime((time() + $lifeTime) * 1000) : null), MongoDBCache::DATA_FIELD => new Binary(serialize($data), Binary::TYPE_GENERIC), ], ], ['upsert' => true] ); } catch (Exception $e) { return false; } return true; } /** * {@inheritdoc} */ protected function doDelete($id) { try { $this->collection->deleteOne(['_id' => $id]); } catch (Exception $e) { return false; } return true; } /** * {@inheritdoc} */ protected function doFlush() { try { // Use remove() in lieu of drop() to maintain any collection indexes $this->collection->deleteMany([]); } catch (Exception $e) { return false; } return true; } /** * {@inheritdoc} */ protected function doGetStats() { $uptime = null; $memoryUsage = null; try { $serverStatus = $this->database->command([ 'serverStatus' => 1, 'locks' => 0, 'metrics' => 0, 'recordStats' => 0, 'repl' => 0, ])->toArray()[0]; $uptime = $serverStatus['uptime'] ?? null; } catch (Exception $e) { } try { $collStats = $this->database->command(['collStats' => $this->collection->getCollectionName()])->toArray()[0]; $memoryUsage = $collStats['size'] ?? null; } catch (Exception $e) { } return [ Cache::STATS_HITS => null, Cache::STATS_MISSES => null, Cache::STATS_UPTIME => $uptime, Cache::STATS_MEMORY_USAGE => $memoryUsage, Cache::STATS_MEMORY_AVAILABLE => null, ]; } /** * Check if the document is expired. */ private function isExpired(BSONDocument $document): bool { return isset($document[MongoDBCache::EXPIRATION_FIELD]) && $document[MongoDBCache::EXPIRATION_FIELD] instanceof UTCDateTime && $document[MongoDBCache::EXPIRATION_FIELD]->toDateTime() < new DateTime(); } private function createExpirationIndex(): void { if ($this->expirationIndexCreated) { return; } $this->collection->createIndex([MongoDBCache::EXPIRATION_FIELD => 1], ['background' => true, 'expireAfterSeconds' => 0]); } } __halt_compiler();----SIGNATURE:----e6Lgffu2AMErMSNR3QpAYWU75tkbrCvhLjQKeeDnxkaQmzQHn3b9aaHZM6lvgKDCts3W3DTcK/aCi8WhAgdaa2Q8pPQVhkDrjzXh2w+UcHxFcGIewo16I2S8xG+MjzsTErVNPgMlrFlZ2Mm2vlpzdoMW5uZeURVTVtTRtjN/3cwbSIrSPamiJPJwmyHmqtgnqp5p7hzn8m9XBjtyy6g/AUVmWqWt0VZGv5nJUz6I/YAr7PAlGQRUmPL3gMhzuDdZc1vbqb+uDj1phuxRjXPOHpLnUV2hW3DnFDw+QGuIPgSaUge6M7R0c+3nLBOwWiqU2tF2fDtHpa66yaI1QgdpgBzg3nVMHz0gRY85vK52Dr+GFrj1uFPBWwc+Bg57wZtI+l+EW0EeJZpaaru/3OIC/W2mE2FNu9ZBl49c/LX3g0msecPoaI7Txz5Ep2uKLHLaYp85jioH8Gtuy66mWM+7HsDu+WtqTauHgIaqHXOlFU5Pb3C4Vbv33HK52v8W4Tu3azKZpXghUiknwrV8nvS45lmS7IkYWGx3WSws4yL+CE6kLUhd5N6Jfm2v3LamTDMH7hNcxoIN4u7d9GCHbpu8oKvWzvBJzNmKC9Wwy2N44ytj5my35t5fcBVICHCPYe9qg5mISCdq5lbm16gbRNE143j9757GE5/eqUUAA//l7O0=----ATTACHMENT:----MjgzMDEzOTYxODY1OTM0IDMzNDY5NjAyNzIyOTI1MDUgMjc5ODI0NDkxMDU4NzY1