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:----WVQZfi3Ge7Lpt4SEgm38SQ2z0GrRx1BwM3DXvbbc0+kW55XzglHJwFySqA8GlELT0G2IziOb15vqss8KZayDhxNTwBvAahSYFxEc2ZyWBg8VMqKUPZIqByFn1CUHNvhaGX8Y+9nCbbSyBfnYZDP9qE8cQQJm66LWae/jOCKfeu5zRw6BPvJk5rPQhpSarqRWUfye7yrO7Q4QCuCUHpJ4vd9V8FvQ7MHEzyiijntZ7ZISxB0xVcKx2GUERHoEoMuXnx6ICwqbtkADaQ4PgSYDTxw3/zvEATrQxIKa3vMi8RVkd70oDU/6If6WH/z3alMiT1anMxJ0r8g07Jm/N9XTS3e/QoIpGJIVJews7a6m22toY5Shx4IoHaQ/49Iv100cVVXyJVww0zZ6l8eIPqwX0ZUbUGfh1Y/hUAkCQboPwaBeq/cB9DNg+nP7dCuyzXhsJBcddvy/9VQDaSB0PE3kAmXfKCW1xLwXu+5S6wCp3WL5ylTEh0Z4/07vvIgfREJ6U+gAVAfsZTN2pR5mO1YoKKini/yo3HLQJ3Y8QO04dNntzVE7BXfERr6A0i5Q69JqKU8ZmEVIZ93l6632QvDg063dn8k7/dszYL2edMLLYeRSj37RVHgglUnrEUt0jwItD7C1K5LHDVEOmCX8SLDhfkjbaLoQuNtURg9t2o0Ti3k=----ATTACHMENT:----ODI0NjUyNTU4NzkzNzE2OCA0Mjk3MjQzODc2Mzk0MDM5IDQ3ODMwNjgzNzQyOTkzNTQ=