CFCouchbase SDK
  • Introduction
  • What's New With 2.2.0
  • What's New With 2.0.0
  • About This Book
  • Authors
  • Overview
  • Installation
    • ColdBox Module
    • Traditional Apps
  • Configuration
    • Settings
    • Structure
    • Summary
  • Usage
    • Storing Documents
    • Storage Durability
    • Retrieving Documents
    • Data Serialization
    • Components
      • Auto Inflation
      • Manual Inflation
      • Custom Serialization
      • Binary
    • Custom Transformers
    • Executing Queries
      • View Queries
      • n1ql Queries
      • Query Options
      • Filter Closures
      • Transform Closures
      • Return Types
    • Managing Views
    • Working With Futures
  • Help & Support
Powered by GitBook
On this page
  • The Mapping
  • WireBox
  • Shutting Down The Client

Was this helpful?

Edit on GitHub
Export as PDF
  1. Installation

Traditional Apps

PreviousColdBox ModuleNextConfiguration

Last updated 7 years ago

Was this helpful?

Download the SDK from the following sources or use CommandBox: box install cfcouchbase to install the SDK

  • Official Releases:

  • Source: Github

  • Bleeding Edge + More:

The Mapping

The CFCouchase SDK is contained in a single folder. The easiest way to install it is to copy cfcouchbase in the web root. For a more secure installation, place it outside the web root and create a mapping called cfcouchbase.

this.mappings[ '/cfcouchbase' ] = 'C:\path\to\cfcouchbase';

Now that the code is in place, all you need to do is create an instance of cfcouchbase.CouchbaseClient for each bucket you want to connect to. The CouchbaseClient class is thread safe and you only need one instance per bucket for your entire application. It is recommended that you store the instantiated client in a persistent scope such as application when your app starts up so you can access it easily.

public boolean function onApplicationStart(){
    application.couchbase = new cfcouchbase.CouchbaseClient();
    return true;
}

WireBox

However, we would recommend you use a dependency injection framework like to create and manage your Couchbase Client:

// Map our Couchbase Client via WireBox Binder
map( "CouchbaseClient" )
    .to( "cfcouchbase.CouchbaseClient" )
    .initArg( name="config", value={} )
    .asSingleton();

Shutting Down The Client

When you are finished with the client, you need to call its shutdown() method to close open connections to the Couchbase server. The following code sample will wait up to 10 seconds for connections to be closed.

public boolean function onApplicationEnd(){        
    application.couchbase.shutdown( 10 );
    return true;
}

Danger: Each Couchbase bucket operates independently and uses its own authentication mechanisms. You need an instance of CouchbaseClient for each bucket you want to interact with. It is also extremely important that you shutdown the clients whenever your application goes down in order to gracefully shutdown connections, else your server might degrade.

http://www.ortussolutions.com/products/cfcouchbase
https://github.com/Ortus-Solutions/cfcouchbase-sdk
http://integration.stg.ortussolutions.com/artifacts/ortussolutions/cfcouchbase/
WireBox