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:----pxqktQ15OJ4z2ALlhklRlhvrXoPfvuVWk6tJL/wzLcfS2vWdV+GlJ3ogQzvdz0Goa+ZlChzpeu0sm2KxCbbtk7ITinaQHVKrWB1XA1iZ03J0ovDWMkf/u+g/QE8bxPAjoykJqfmu7SMRVGVBRvCBTyxqL3LGdmDr2ZPfdGGWEF9JW39nFQdzgaGA86rO/V96pYFledlpM7irZTYIjR3m8dm4CWZ1mG3ZRAHJhGQ37Y2rL3KKzP7tG0lrzZHJGpyL2KgCONG6CiCBMThmjw5lGs7hNlYCTtpFP9cMl+IjdHFYyKzekOD1q9fsqdqWACelP4u5HDNDQkTTG9x11to67JepXh+q0o7uwSKoAoTtIvy2VTjTrgkAZOKX9iLr1q1mUrrV/7zjLKguXuxD56+5URcdezfhYXatfUt57uMc0Sbfjj2GXfU3yZEgjCeJKb4SkOV81kWF32CRZKKnD8/sG3q365fz++5DSYTfYSbkPqBvuXHrN65bPlKs4cIjtIAv6oTsEY/3Jtt9tZE9264CJj55oblMndP2WxMNZKNu7yMramZhviOF+rXuOKL5imYEoAstFAoDHLpsLbtC3vbOhPfBP0NLm26RNc7CUoocJQOYpWu0mC2lizVNxDppZ8RtgrVYuNQn6xFE/2In+51L9DaiQo3HzIXbLEXlb81wW4c=----ATTACHMENT:----NzQxOTcyOTQ1NjUxNTc0MCAxNjk0MzQ2NjI5MjU1NjQ1IDYyNzQxNDI2ODc0MTU0NA==