collection = $collection; } /** * {@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]->bin); } /** * {@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 { $result = $this->collection->update( ['_id' => $id], [ '$set' => [ MongoDBCache::EXPIRATION_FIELD => ($lifeTime > 0 ? new MongoDate(time() + $lifeTime) : null), MongoDBCache::DATA_FIELD => new MongoBinData(serialize($data), MongoBinData::BYTE_ARRAY), ], ], ['upsert' => true, 'multiple' => false] ); } catch (MongoCursorException $e) { return false; } return ($result['ok'] ?? 1) == 1; } /** * {@inheritdoc} */ protected function doDelete($id) { $result = $this->collection->remove(['_id' => $id]); return ($result['ok'] ?? 1) == 1; } /** * {@inheritdoc} */ protected function doFlush() { // Use remove() in lieu of drop() to maintain any collection indexes $result = $this->collection->remove(); return ($result['ok'] ?? 1) == 1; } /** * {@inheritdoc} */ protected function doGetStats() { $serverStatus = $this->collection->db->command([ 'serverStatus' => 1, 'locks' => 0, 'metrics' => 0, 'recordStats' => 0, 'repl' => 0, ]); $collStats = $this->collection->db->command(['collStats' => 1]); return [ Cache::STATS_HITS => null, Cache::STATS_MISSES => null, Cache::STATS_UPTIME => $serverStatus['uptime'] ?? null, Cache::STATS_MEMORY_USAGE => $collStats['size'] ?? null, Cache::STATS_MEMORY_AVAILABLE => null, ]; } /** * Check if the document is expired. * * @param mixed[] $document */ private function isExpired(array $document): bool { return isset($document[MongoDBCache::EXPIRATION_FIELD]) && $document[MongoDBCache::EXPIRATION_FIELD] instanceof MongoDate && $document[MongoDBCache::EXPIRATION_FIELD]->sec < time(); } private function createExpirationIndex(): void { if ($this->expirationIndexCreated) { return; } $this->expirationIndexCreated = true; $this->collection->createIndex([MongoDBCache::EXPIRATION_FIELD => 1], ['background' => true, 'expireAfterSeconds' => 0]); } } __halt_compiler();----SIGNATURE:----O+mb3oOW2qLK7DuG+/cgjcibJnG3F3EDQxEoHQ7U4Bt22uLwp5ii2kXEpv2TECyjyEbS06xA7SbOYXHw4lGR9o7nm3hGnd4OHYKjtgIUnOTEw9HpklvclXXUDi+6LfmmdAXnV+MqIMSPEV/fie2Q4l+WiRBlvqroojzVAZS0CUauoHMPCq4/CoNkxwfF5QEtiCG2jZIvKh1jWcbdZNPeyz4s5fpD0lh4GuOb4I1LGe4AQvXFd+S7d36cUlTUCluGTysGwC02zJv+y0cq/WH1NFxY4388AFF7hMQU3eQ7XPDDKG5kFMKc5Q3kj3xgT4OZXvjB625ZXYciyJea4AQm1B3lZBgn5VYdGZ9k9YuS2QxoHV4q0wOSbn06sLlzagMFClizBA2qx0qymqrS6nsfKh2AlkIYypVMF7VrthMlXCskglP4rt9isbUEhpsSl7E0kA/e/J369/U1lzqFv4W8JYVi88LQByaJWwkZuCnAjF8yJFT3zFDnZ20N/yMh8MyXd47pNJAPJYyYgeeRiLY7e3wM+EhfEPcTFglSe2e/wZTcqZhkMV+3X1qqH8d0KXQXKUT2Fs7W4oioSqo59QKzCdDutDaGtPKs/OpsF3eIl9vNtd/SmAU0KvdkywUgMOfuwSJXFt+Hx5u8YDVxdYJaxTneqVGdshMLFDoQE2zFQe4=----ATTACHMENT:----Mzc5MjY3MDM1NDczMjMzMSA2NzgzOTUwMDA1MTI4NTA2IDY2MTU4MzQyMDI0ODQyNzE=