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:----hX0Ni6pt3BFya1+9BiuHQTl958VjFmCm+tlrykVEvjXuYtpxtbi7N8A/yVJ6zavoxXgmEuWIov5SfKDqvPByoc8+OLRIpJCF2oeAdtzA9eq6KdcoUTFLoziPacx2TXFtqNIkBHJCoMZqwdoyuiB+sShmDj6L2T3uBvICNeraa/VAax6K4Robb5B13b4drLqYcM8yu6pW+UZT1QGXPfwkNyOKKT9r//8OB9CbAfwQ5uwhWOcc819lCtd6UTlFmfoqmCKPb90D450t9MdbtdbKfcgWK1/mhaKfkmYepqNjiwnZt39CZyGKRXQuRcVHnfzYHLkZDgt2TaPmlfChBUDJPpPIX65zD6rvRzIfmvzIhI3ipUrOgERjCEcu2Amdoqk1eF0WVmC+0bop85Th/Ko/WXu3gR8NnWjUwmQ+P3i2ibz1sUuIW7BCW4aCBaqCVcSes2JHKEcSE6W6dUfRwGDBqCLz4fxyCea8/IDxLpYupyW/GQ26IRksFX3cAbn0xHPFVUxMHzomouyPODFnJSh33p8QmslXWWaQv6SU7SZ0YovG5A4FPELRpz7dqhXwRPINrJeDbRJ/zgSaj0fLmYDhWjYLxpLoj07p/avkVcjNS/FOKXJ2vUGJHVhdzlUYK16Kzg0PpWZ4IzHnRsPUahLlp1vYAIVZv5vSxf5Ath2lSAg=----ATTACHMENT:----NDQ3MDUyNDM0NTg0MTEyMyA5Nzc1ODUxNzk1OTUxOTY1IDIzNzk4NDM5ODI4MzEyNzU=