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:----XUrIqE8UqWaEMepwOFGsjbHDDNpt0tv9YMRFQPorvzvAITOhGLYwhiDg3Rd1kLlAZt3B0ROvHXQg6tQ6B0M/jwrDgVJETqiJ/Rd/eqn8pvT5d3yFxXxIOShnKV3NYpr7gUldxa56fNGwAplFwbTBxWjSgtbNO/R1e5f5DbuEt8L2p0joSpF1Wui9jfzUpuP7RhT3kxUPqmjJbJNWf7ai79bN3SioRKdnVb9FIuUzrTdIW2JK6BngxnInaZF1dYvegp/dJgM1TZw97b0FmPU23ui2rEC42Wa7AC4JuG9jJF6ar8VFgwETVVpBy8OubkIXOfquei3Zo4jL5EkOwhjkG7r3jvc24nnBGbQxK7M8kl4bBsRHhU6UGKtrULG53yZixtVPKdrPoDr0sKX9EnPr5+Z025KW9TwdSMNdiZMUPR+8irob/uzzGIewjQp5Ey0FIWqx9g2bqMzQg+g+sI/Su9MrSNC3P5ygnJdgxTz+TutbWxQARgjXpeeKfFZEQi5Y2y2XmWDIL/dEXpJd+q+PQC+JvQzxu94MLkGTD13zTYaNs2BJqbsbGWm0O4HAKF+/3zhfaSXXTYJW7bC/qJNCK/6ayXsWQSIOpHxNvg2ivccGDJtihYwvLXlQlXF55jIYQmxDRgCWuB7aUGW+CEj06u9+J8Rgzi37h8kA9qFKXmc=----ATTACHMENT:----NTkxODQ3MzA2MjA1NTU0MSA1ODQ4NzQ4NzIxNTk5ODIzIDQ2NDgwNTk3ODQ4MTEyNDM=