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:----hU2gSzIWx/iPQEjrvyFF9zVEAk8VIvLVNfwW58IYUDpkV4a5+2L2cHJ/QDmEfUC7WDUNT78+yuNTQEQd5wlwoC0shvZjDgd35g9fyOeNWUjRFx5yhr6IEe+MRJZZK54wkzV60i/MxXj8hfZf9BVb1c0UvMzws37MCh0ZUGAXIgvG6xe9Bbj/Z9am8K8Ub7NYsVCxuOnVOLAy1CAe4X0Yf9duFgwDJfIn7OGsQg0VedkPrZbmm3LS6dBvll0gRt9xrVcj/Vhyq2SglQ9xPpLWhoJvlwI7NKwAl3r5pJRmnB5AnGRXWS0XL6tXMuV4YAr7wDU9trYP3lCI7KpsDFiwZ8CCzMRur5vv9+3yaTgmceNXpZQ5qxsGFrEZx16izD80+nZZ49X0kpE9Ww5XYBiRz3zuu2GKhiZAvojZs28ieTJxJYC013yhVff9X/3RxqlFLp9omhdVSsDmldL/dOcSL1c17PCb69aRsyTiimMaTclDTtPHLF2X70fxEMa1Z4GLeJt6bmsi999/JWwu5pyhU2PfH6wMqdZDe34qhQLXU6u7eXFt5B5FXc+lfCq0PTchqidd9En9WLOpQMrNiKjQ/Xdv2wqv5ugmO91hZx2cn+CbJ41jL3g0N/9mQdFmPYFfnneSBnzIDUTyJdkSpQPCg2UQ+IhwLqnY/qOZqdiwKT0=----ATTACHMENT:----NjQ3MDE2NDY3Njc2ODcxNiA5Mjg0MDA2MTM3NDg0MTQyIDM5NTUzNjQ3NDQ0Nzc0MTI=