|
| 1 | +.. index:: |
| 2 | + single: Cache Pool |
| 3 | + single: Couchabase Cache |
| 4 | + |
| 5 | +.. _couchbase-adapter: |
| 6 | + |
| 7 | +Couchbase Cache Adapter |
| 8 | +======================= |
| 9 | + |
| 10 | +This adapter stores the values in-memory using one (or more) `Couchbase server`_ |
| 11 | +instances. Unlike the :ref:`APCu adapter <apcu-adapter>`, and similarly to the |
| 12 | +:ref:`Memcached adapter <memcached-adapter>`, it is not limited to the current server's |
| 13 | +shared memory; you can store contents independent of your PHP environment. |
| 14 | +The ability to utilize a cluster of servers to provide redundancy and/or fail-over |
| 15 | +is also available. |
| 16 | + |
| 17 | +.. caution:: |
| 18 | + |
| 19 | + **Requirements:** The `Couchbase PHP extension`_ as well as a `Couchbase server`_ |
| 20 | + must be installed, active, and running to use this adapter. Version ``2.6`` or |
| 21 | + greater of the `Couchbase PHP extension`_ is required for this adapter. |
| 22 | + |
| 23 | +This adapter expects a `Couchbase Bucket`_ instance to be passed as the first |
| 24 | +parameter. A namespace and default cache lifetime can optionally be passed as |
| 25 | +the second and third parameters:: |
| 26 | + |
| 27 | + use Symfony\Component\Cache\Adapter\CouchbaseBucketAdapter; |
| 28 | + |
| 29 | + $cache = new CouchbaseBucketAdapter( |
| 30 | + // the client object that sets options and adds the server instance(s) |
| 31 | + \CouchbaseBucket $client, |
| 32 | + |
| 33 | + // the name of bucket |
| 34 | + string $bucket, |
| 35 | + |
| 36 | + // a string prefixed to the keys of the items stored in this cache |
| 37 | + $namespace = '', |
| 38 | + |
| 39 | + // the default lifetime (in seconds) for cache items that do not define their |
| 40 | + // own lifetime, with a value 0 causing items to be stored indefinitely |
| 41 | + $defaultLifetime = 0, |
| 42 | + ); |
| 43 | + |
| 44 | + |
| 45 | +Configure the Connection |
| 46 | +------------------------ |
| 47 | + |
| 48 | +The :method:`Symfony\\Component\\Cache\\Adapter\\CouchbaseBucketAdapter::createConnection` |
| 49 | +helper method allows creating and configuring a `Couchbase Bucket`_ class instance using a |
| 50 | +`Data Source Name (DSN)`_ or an array of DSNs:: |
| 51 | + |
| 52 | + use Symfony\Component\Cache\Adapter\CouchbaseBucketAdapter; |
| 53 | + |
| 54 | + // pass a single DSN string to register a single server with the client |
| 55 | + $client = CouchbaseBucketAdapter::createConnection( |
| 56 | + 'couchbase://localhost' |
| 57 | + // the DSN can include config options (pass them as a query string): |
| 58 | + // 'couchbase://localhost:11210?operationTimeout=10' |
| 59 | + // 'couchbase://localhost:11210?operationTimeout=10&configTimout=20' |
| 60 | + ); |
| 61 | + |
| 62 | + // pass an array of DSN strings to register multiple servers with the client |
| 63 | + $client = CouchbaseBucketAdapter::createConnection([ |
| 64 | + 'couchbase://10.0.0.100', |
| 65 | + 'couchbase://10.0.0.101', |
| 66 | + 'couchbase://10.0.0.102', |
| 67 | + // etc... |
| 68 | + ]); |
| 69 | + |
| 70 | + // a single DSN can define multiple servers using the following syntax: |
| 71 | + // host[hostname-or-IP:port] (where port is optional). Sockets must include a trailing ':' |
| 72 | + $client = CouchbaseBucketAdapter::createConnection( |
| 73 | + 'couchbase:?host[localhost]&host[localhost:12345]' |
| 74 | + ); |
| 75 | + |
| 76 | + |
| 77 | +Configure the Options |
| 78 | +--------------------- |
| 79 | + |
| 80 | +The :method:`Symfony\\Component\\Cache\\Adapter\\CouchbaseBucketAdapter::createConnection` |
| 81 | +helper method also accepts an array of options as its second argument. The |
| 82 | +expected format is an associative array of ``key => value`` pairs representing |
| 83 | +option names and their respective values:: |
| 84 | + |
| 85 | + use Symfony\Component\Cache\Adapter\CouchbaseBucketAdapter; |
| 86 | + |
| 87 | + $client = CouchbaseBucketAdapter::createConnection( |
| 88 | + // a DSN string or an array of DSN strings |
| 89 | + [], |
| 90 | + |
| 91 | + // associative array of configuration options |
| 92 | + [ |
| 93 | + 'username' => 'xxxxxx', |
| 94 | + 'password' => 'yyyyyy', |
| 95 | + 'configTimeout' => '100', |
| 96 | + ] |
| 97 | + ); |
| 98 | + |
| 99 | +Available Options |
| 100 | +~~~~~~~~~~~~~~~~~ |
| 101 | + |
| 102 | +``username`` (type: ``string``) |
| 103 | + Username for connection ``CoucbaseCluster``. |
| 104 | + |
| 105 | +``password`` (type: ``string``) |
| 106 | + Password of connection ``CouchbaseCluster``. |
| 107 | + |
| 108 | +``operationTimeout`` (type: ``int``, default: ``2500000``) |
| 109 | + The operation timeout (in microseconds) is the maximum amount of time the library will |
| 110 | + wait for an operation to receive a response before invoking its callback with a failure status. |
| 111 | + |
| 112 | +``configTimeout`` (type: ``int``, default: ``5000000``) |
| 113 | + How long (in microseconds) the client will wait to obtain the initial configuration. |
| 114 | + |
| 115 | +``configNodeTimeout`` (type: ``int``, default: ``2000000``) |
| 116 | + Per-node configuration timeout (in microseconds). |
| 117 | + |
| 118 | +``viewTimeout`` (type: ``int``, default: ``75000000``) |
| 119 | + The I/O timeout (in microseconds) for HTTP requests to Couchbase Views API. |
| 120 | + |
| 121 | +``httpTimeout`` (type: ``int``, default: ``75000000``) |
| 122 | + The I/O timeout (in microseconds) for HTTP queries (management API). |
| 123 | + |
| 124 | +``configDelay`` (type: ``int``, default: ``10000``) |
| 125 | + Config refresh throttling |
| 126 | + Modify the amount of time (in microseconds) before the configiration error threshold will forcefully be set to its maximum number forcing a configuration refresh. |
| 127 | + |
| 128 | +``htconfigIdleTimeout`` (type: ``int``, default: ``4294967295``) |
| 129 | + Idling/Persistence for HTTP bootstrap (in microseconds). |
| 130 | + |
| 131 | +``durabilityInterval`` (type: ``int``, default: ``100000``) |
| 132 | + The time (in microseconds) the client will wait between repeated probes to a given server. |
| 133 | + |
| 134 | +``durabilityTimeout`` (type: ``int``, default: ``5000000``) |
| 135 | + The time (in microseconds) the client will spend sending repeated probes to a given key's vBucket masters and replicas before they are deemed not to have satisfied the durability requirements. |
| 136 | + |
| 137 | +.. tip:: |
| 138 | + |
| 139 | + Reference the `Couchbase Bucket`_ extension's `predefined constants`_ documentation |
| 140 | + for additional information about the available options. |
| 141 | + |
| 142 | +.. _`Couchbase PHP extension`: https://docs.couchbase.com/sdk-api/couchbase-php-client-2.6.0/files/couchbase.html |
| 143 | +.. _`predefined constants`: https://docs.couchbase.com/sdk-api/couchbase-php-client-2.6.0/classes/Couchbase.Bucket.html |
| 144 | +.. _`Couchbase server`: https://couchbase.com/ |
| 145 | +.. _`Couchbase Bucket`: https://docs.couchbase.com/sdk-api/couchbase-php-client-2.6.0/classes/Couchbase.Bucket.html |
| 146 | +.. _`Data Source Name (DSN)`: https://en.wikipedia.org/wiki/Data_source_name |
0 commit comments