Skip to content

Commit 5eb942c

Browse files
committed
Add documentation CouchbaseBucketAdapter for cache system.
1 parent c82bee0 commit 5eb942c

File tree

1 file changed

+135
-0
lines changed

1 file changed

+135
-0
lines changed
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
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+
\CouchbaseCluster $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 (i.e.
41+
// until MemcachedAdapter::clear() is invoked or the server(s) are restarted)
42+
$defaultLifetime = 0,
43+
44+
// associative array of configuration options
45+
array $options = [
46+
'operationTimeout' => 10,
47+
'configTimeout' => 5,
48+
'configNodeTimeout' => 20,
49+
]
50+
);
51+
52+
53+
Available Options
54+
~~~~~~~~~~~~~~~~~
55+
56+
``operationTimeout`` (type: ``int``, default: ``2500000``)
57+
The operation timeout (in microseconds) is the maximum amount of time the library will
58+
wait for an operation to receive a response before invoking its callback with a failure status.
59+
60+
``configTimeout`` (type: ``int``, default: ``5000000``)
61+
How long (in microseconds) the client will wait to obtain the initial configuration.
62+
63+
``configNodeTimeout`` (type: ``int``, default: ``2000000``)
64+
Per-node configuration timeout (in microseconds).
65+
66+
Configure the Connection
67+
------------------------
68+
69+
The :method:`Symfony\\Component\\Cache\\Adapter\\CouchbaseBucketAdapter::createConnection`
70+
helper method allows creating and configuring a `Couchbase Bucket`_ class instance using a
71+
`Data Source Name (DSN)`_ or an array of DSNs::
72+
73+
use Symfony\Component\Cache\Adapter\CouchbaseBucketAdapter;
74+
75+
// pass an array of DSN strings to register multiple servers with the client
76+
$client = MemcachedAdapter::createConnection([
77+
'couchbase://10.0.0.100',
78+
'couchbase://10.0.0.101',
79+
'couchbase://10.0.0.102',
80+
// etc...
81+
]);
82+
83+
// a single DSN can define multiple servers using the following syntax:
84+
// host[hostname-or-IP:port] (where port is optional). Sockets must include a trailing ':'
85+
$client = MemcachedAdapter::createConnection(
86+
'couchbase:?host[localhost]&host[localhost:12345]&host[/some/memcached.sock:]=3'
87+
);
88+
89+
90+
Configure the Options
91+
---------------------
92+
93+
The :method:`Symfony\\Component\\Cache\\Adapter\\CouchbaseBucketAdapter::createConnection`
94+
helper method also accepts an array of options as its second argument. The
95+
expected format is an associative array of ``key => value`` pairs representing
96+
option names and their respective values::
97+
98+
use Symfony\Component\Cache\Adapter\CouchbaseBucketAdapter;
99+
100+
$client = MemcachedAdapter::createConnection(
101+
// a DSN string or an array of DSN strings
102+
[],
103+
104+
// associative array of configuration options
105+
[
106+
'username' => 'xxxxxx',
107+
'password' => 'yyyyyy',
108+
]
109+
);
110+
111+
Available Options
112+
~~~~~~~~~~~~~~~~~
113+
114+
``username`` (type: ``string``, default: ````)
115+
Username for connection ``CoucbaseCluster``.
116+
117+
``password`` (type: ``string``, default: ````)
118+
Password of connection ``CouchbaseCluster``.
119+
120+
121+
.. tip::
122+
123+
Reference the `Memcached`_ extension's `predefined constants`_ documentation
124+
for additional information about the available options.
125+
126+
.. _`Transmission Control Protocol (TCP)`: https://en.wikipedia.org/wiki/Transmission_Control_Protocol
127+
.. _`User Datagram Protocol (UDP)`: https://en.wikipedia.org/wiki/User_Datagram_Protocol
128+
.. _`no-delay`: https://en.wikipedia.org/wiki/TCP_NODELAY
129+
.. _`keep-alive`: https://en.wikipedia.org/wiki/Keepalive
130+
.. _`Couchbase PHP extension`: https://docs.couchbase.com/sdk-api/couchbase-php-client-2.6.0/files/couchbase.html
131+
.. _`predefined constants`: http://php.net/manual/en/memcached.constants.php
132+
.. _`Couchbase server`: https://couchbase.com/
133+
.. _`Couchbase Bucket`: https://docs.couchbase.com/sdk-api/couchbase-php-client-2.6.0/classes/Couchbase.Bucket.html
134+
.. _`Data Source Name (DSN)`: https://en.wikipedia.org/wiki/Data_source_name
135+
.. _`Domain Name System (DNS)`: https://en.wikipedia.org/wiki/Domain_Name_System

0 commit comments

Comments
 (0)