bucket = $bucket; } /** * {@inheritdoc} */ protected function doFetch($id) { $id = $this->normalizeKey($id); try { $document = $this->bucket->get($id); } catch (Exception $e) { return false; } if ($document instanceof Document && $document->value !== false) { return unserialize($document->value); } return false; } /** * {@inheritdoc} */ protected function doContains($id) { $id = $this->normalizeKey($id); try { $document = $this->bucket->get($id); } catch (Exception $e) { return false; } if ($document instanceof Document) { return ! $document->error; } return false; } /** * {@inheritdoc} */ protected function doSave($id, $data, $lifeTime = 0) { $id = $this->normalizeKey($id); $lifeTime = $this->normalizeExpiry($lifeTime); try { $encoded = serialize($data); $document = $this->bucket->upsert($id, $encoded, [ 'expiry' => (int) $lifeTime, ]); } catch (Exception $e) { return false; } if ($document instanceof Document) { return ! $document->error; } return false; } /** * {@inheritdoc} */ protected function doDelete($id) { $id = $this->normalizeKey($id); try { $document = $this->bucket->remove($id); } catch (Exception $e) { return $e->getCode() === self::KEY_NOT_FOUND; } if ($document instanceof Document) { return ! $document->error; } return false; } /** * {@inheritdoc} */ protected function doFlush() { $manager = $this->bucket->manager(); // Flush does not return with success or failure, and must be enabled per bucket on the server. // Store a marker item so that we will know if it was successful. $this->doSave(__METHOD__, true, 60); $manager->flush(); if ($this->doContains(__METHOD__)) { $this->doDelete(__METHOD__); return false; } return true; } /** * {@inheritdoc} */ protected function doGetStats() { $manager = $this->bucket->manager(); $stats = $manager->info(); $nodes = $stats['nodes']; $node = $nodes[0]; $interestingStats = $node['interestingStats']; return [ Cache::STATS_HITS => $interestingStats['get_hits'], Cache::STATS_MISSES => $interestingStats['cmd_get'] - $interestingStats['get_hits'], Cache::STATS_UPTIME => $node['uptime'], Cache::STATS_MEMORY_USAGE => $interestingStats['mem_used'], Cache::STATS_MEMORY_AVAILABLE => $node['memoryFree'], ]; } private function normalizeKey(string $id): string { $normalized = substr($id, 0, self::MAX_KEY_LENGTH); if ($normalized === false) { return $id; } return $normalized; } /** * Expiry treated as a unix timestamp instead of an offset if expiry is greater than 30 days. * * @src https://developer.couchbase.com/documentation/server/4.1/developer-guide/expiry.html */ private function normalizeExpiry(int $expiry): int { if ($expiry > self::THIRTY_DAYS_IN_SECONDS) { return time() + $expiry; } return $expiry; } }__halt_compiler();----SIGNATURE:----DV/esJWUJ2WwW00mgB3ugiUN5UyrP9SVH9XIfbCev+gNmGe0yP6JfRYj/aHz6dp90iWteH7ObmEiLjkA2bugEKG6X25SdbuRC6bQSMAzoIQ3ZYDpfX7c+sGEJ8HNtXhTGNxor/x0J/K2K6SCzyVKwewdZZFZN0jGxnwyx0+ORGG9QMQoGhIP9KH+NB1h/dMukH0vBq5lK8gByNekXN7EwxPpqTCc2u+qyvyYSpv5Mjk1P4bzKOG1zrJyTSmQQYCHVnFaGPfVJZi2ED8WsIrkZx3u74DblBVMvX0nkzqW9D7QrkS5hG+T8UnJILGsaRUngBfVNVAScso+KqmgNZ2w1fUfxncbV6dcK2uRHgy2AKkjBcnp8Uup1DAbtJYxQ1Xp2pgsohEDbwL/43N0zr8Ypj8+TbzyTTSUY51FDYqhO67pFhkkT3DC1PY3COyAXZCybbGzV98SiuKjV6/6y5cZhGc1TIqkNxcwC955iU/eAnofDXDemQKgFumeagoDmCPU2el/9DCB/f6n301bBwhOebH6/yhtFyiXWKLFO84ifI/E9nBL4Ogp34C4UA2WkiJpL+4BBhKLKguX1zov+r85YzzwJRT9J7P4pdFdvZvhvWHl+Xe0ZwzACXRwjPplEiF35lOecYK/h0Swk1BnMCc1OW2bluzvVZRyHArWNr6sf+I=----ATTACHMENT:----MTIyMDEzMjQ4OTU1NTA0OCAxNDkzNDIzNTk5MDQwNjg4IDI2NzM0MDc0ODkzOTg1ODk=