Skip to content
  • About
    • What is Symfony?
    • Community
    • News
    • Contributing
    • Support
  • Documentation
    • Symfony Docs
    • Symfony Book
    • Screencasts
    • Symfony Bundles
    • Symfony Cloud
    • Training
  • Services
    • Platform.sh for Symfony Best platform to deploy Symfony apps
    • SymfonyInsight Automatic quality checks for your apps
    • Symfony Certification Prove your knowledge and boost your career
    • SensioLabs Professional services to help you with Symfony
    • Blackfire Profile and monitor performance of your apps
  • Other
  • Blog
  • Download
sponsored by
  1. Home
  2. Documentation
  3. Cache
  4. Couchbase Collection Cache Adapter

Couchbase Collection Cache Adapter

Edit this page

This adapter stores the values in-memory using one (or more) Couchbase server instances. Unlike the APCu adapter, and similarly to the Memcached adapter, it is not limited to the current server's shared memory; you can store contents independent of your PHP environment. The ability to utilize a cluster of servers to provide redundancy and/or fail-over is also available.

Caution

Requirements: The Couchbase PHP extension as well as a Couchbase server must be installed, active, and running to use this adapter. Version 3.0 or greater of the Couchbase PHP extension is required for this adapter.

This adapter expects a Couchbase Collection instance to be passed as the first parameter. A namespace and default cache lifetime can optionally be passed as the second and third parameters:

1
2
3
4
5
6
7
8
9
10
11
12
13
use Symfony\Component\Cache\Adapter\CouchbaseCollectionAdapter;

$cache = new CouchbaseCollectionAdapter(
    // the client object that sets options and adds the server instance(s)
    $client,

    // a string prefixed to the keys of the items stored in this cache
    $namespace,

    // the default lifetime (in seconds) for cache items that do not define their
    // own lifetime, with a value 0 causing items to be stored indefinitely
    $defaultLifetime
);

Configure the Connection

The createConnection() helper method allows creating and configuring a Couchbase Collection class instance using a Data Source Name (DSN) or an array of DSNs:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
use Symfony\Component\Cache\Adapter\CouchbaseCollectionAdapter;

// pass a single DSN string to register a single server with the client
$client = CouchbaseCollectionAdapter::createConnection(
    'couchbase://localhost'
    // the DSN can include config options (pass them as a query string):
    // 'couchbase://localhost:11210?operationTimeout=10'
    // 'couchbase://localhost:11210?operationTimeout=10&configTimout=20'
);

// pass an array of DSN strings to register multiple servers with the client
$client = CouchbaseCollectionAdapter::createConnection([
    'couchbase://10.0.0.100',
    'couchbase://10.0.0.101',
    'couchbase://10.0.0.102',
    // etc...
]);

// a single DSN can define multiple servers using the following syntax:
// host[hostname-or-IP:port] (where port is optional). Sockets must include a trailing ':'
$client = CouchbaseCollectionAdapter::createConnection(
    'couchbase:?host[localhost]&host[localhost:12345]'
);

Configure the Options

The createConnection() helper method also accepts an array of options as its second argument. The expected format is an associative array of key => value pairs representing option names and their respective values:

1
2
3
4
5
6
7
8
9
10
11
12
13
use Symfony\Component\Cache\Adapter\CouchbaseCollectionAdapter;

$client = CouchbaseCollectionAdapter::createConnection(
    // a DSN string or an array of DSN strings
    [],

    // associative array of configuration options
    [
        'username' => 'xxxxxx',
        'password' => 'yyyyyy',
        'configTimeout' => '100',
    ]
);

Available Options

username (type: string)
Username for connection CouchbaseCluster.
password (type: string)
Password of connection CouchbaseCluster.
operationTimeout (type: int, default: 2500000)
The operation timeout (in microseconds) is the maximum amount of time the library will wait for an operation to receive a response before invoking its callback with a failure status.
configTimeout (type: int, default: 5000000)
How long (in microseconds) the client will wait to obtain the initial configuration.
configNodeTimeout (type: int, default: 2000000)
Per-node configuration timeout (in microseconds).
viewTimeout (type: int, default: 75000000)
The I/O timeout (in microseconds) for HTTP requests to Couchbase Views API.
httpTimeout (type: int, default: 75000000)
The I/O timeout (in microseconds) for HTTP queries (management API).
configDelay (type: int, default: 10000)
Config refresh throttling Modify the amount of time (in microseconds) before the configuration error threshold will forcefully be set to its maximum number forcing a configuration refresh.
htconfigIdleTimeout (type: int, default: 4294967295)
Idling/Persistence for HTTP bootstrap (in microseconds).
durabilityInterval (type: int, default: 100000)
The time (in microseconds) the client will wait between repeated probes to a given server.
durabilityTimeout (type: int, default: 5000000)
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.

Tip

Reference the Couchbase Collection extension's predefined constants documentation for additional information about the available options.

This work, including the code samples, is licensed under a Creative Commons BY-SA 3.0 license.
TOC
    Version

    Symfony 7.1 is backed by

    Become certified from home

    Become certified from home

    The life jacket for your team and your project

    The life jacket for your team and your project

    Version:

    Table of Contents

    • Configure the Connection
    • Configure the Options
      • Available Options

    Symfony footer

    Avatar of Silvio Ginter, a Symfony contributor

    Thanks Silvio Ginter for being a Symfony contributor

    1 commit • 136 lines changed

    View all contributors that help us make Symfony

    Become a Symfony contributor

    Be an active part of the community and contribute ideas, code and bug fixes. Both experts and newcomers are welcome.

    Learn how to contribute

    Symfony™ is a trademark of Symfony SAS. All rights reserved.

    • What is Symfony?

      • What is Symfony?
      • Symfony at a Glance
      • Symfony Components
      • Symfony Releases
      • Security Policy
      • Logo & Screenshots
      • Trademark & Licenses
      • symfony1 Legacy
    • Learn Symfony

      • Symfony Docs
      • Symfony Book
      • Reference
      • Bundles
      • Best Practices
      • Training
      • eLearning Platform
      • Certification
    • Screencasts

      • Learn Symfony
      • Learn PHP
      • Learn JavaScript
      • Learn Drupal
      • Learn RESTful APIs
    • Community

      • Symfony Community
      • SymfonyConnect
      • Events & Meetups
      • Projects using Symfony
      • Contributors
      • Symfony Jobs
      • Backers
      • Code of Conduct
      • Downloads Stats
      • Support
    • Blog

      • All Blog Posts
      • A Week of Symfony
      • Case Studies
      • Cloud
      • Community
      • Conferences
      • Diversity
      • Living on the edge
      • Releases
      • Security Advisories
      • Symfony Insight
      • Twig
      • SensioLabs Blog
    • Services

      • SensioLabs services
      • Train developers
      • Manage your project quality
      • Improve your project performance
      • Host Symfony projects

      Powered by

    Follow Symfony