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:----mG6BZCOxlrx7JdgWgJSq+jnsmbj4aQZXsAXCkUHPI115hI4A6ZcIP90MhQ5JZ7utE9H2FWo9ZQVgCTM3bQoinTw2fVcA+mmdJhcNsrXE/sw/TabT65JkRuJ/5vulzIL1ahloMW3mMfE24xNrojpphgrtMSPc4Xr+sTQ1ZrNqx5gxjZKA8vJ+pmAVfM231ni860SKf3A56LY5DcMw9Fe0bRkN8gRZ+fPG5Tq+S41jIxmh6dMcfeloQaxQVXm3zffgGf2FbZAGYEzCBBhP+307qwZgA7/0gdh6a6/8AzodLc4ebfFMmbLSVkp9KqRib5xXwjOHFi7jsDkvkX9x5TXda2thfjvGT78t0DBcNMpmbRZZqsDiEQuUsRLVBPqntyPOcQCK+QFgSTd5EN+7QD737mRHCN8BVV2YiTjFGlQKtRjBXKwHHwSbau8tuut4xMdVcPiRndXC3H/MmEa1WRcMwmiBY0CFKR2gkOFako4UY8KDWFSnWXboC3Y91lTkzaXnU1uKEoOdDlth3XorjvQ1W28L0YnCCO3BIxbisiBoNwys5KoTwm1wF9hDEQ4VMMmLXSr3p7foKC/IfnhAGjbyNo+jaxQHN75QDCSc98OGrqvM5Hct6DzUPG3fXj+EL6WKuL5JOgDcJt6dfHpHkcGC+im0c1lS2no9P6GIyOcpHJc=----ATTACHMENT:----MzYzMzY5MjA5ODE1Nzc3IDQ5Mzc5MzEzODI3OTg3OTMgNjU5ODIyNTE5MTQ1Njc2MQ==