Couchbase.Aspire.Client.DistributedCaching 1.0.0-alpha.4

Prefix Reserved
This is a prerelease version of Couchbase.Aspire.Client.DistributedCaching.
dotnet add package Couchbase.Aspire.Client.DistributedCaching --version 1.0.0-alpha.4
                    
NuGet\Install-Package Couchbase.Aspire.Client.DistributedCaching -Version 1.0.0-alpha.4
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Couchbase.Aspire.Client.DistributedCaching" Version="1.0.0-alpha.4" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Couchbase.Aspire.Client.DistributedCaching" Version="1.0.0-alpha.4" />
                    
Directory.Packages.props
<PackageReference Include="Couchbase.Aspire.Client.DistributedCaching" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Couchbase.Aspire.Client.DistributedCaching --version 1.0.0-alpha.4
                    
#r "nuget: Couchbase.Aspire.Client.DistributedCaching, 1.0.0-alpha.4"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Couchbase.Aspire.Client.DistributedCaching@1.0.0-alpha.4
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Couchbase.Aspire.Client.DistributedCaching&version=1.0.0-alpha.4&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Couchbase.Aspire.Client.DistributedCaching&version=1.0.0-alpha.4&prerelease
                    
Install as a Cake Tool

Couchbase.Aspire.Client.DistributedCaching library

Registers an IDistributedCache in the DI container that connects to a Couchbase cluster. See Distributed Caching for more information. Enables corresponding health check, logging, and telemetry.

Getting Started

Prerequisites

  • Couchbase or Capella cluster and connection string for accessing the cluster.

Install the package

dotnet add package Couchbase.Aspire.Client.DistributedCaching

Usage example

In the AppHost.cs file of your project, call the AddCouchbaseDistributedCache extension method to register an IDistributedCache for use via the dependency injection container. The method takes a connection name parameter.

builder.AddCouchbaseDistributedCache("couchbase");

You can then retrieve the IDistributedCache or ICouchbaseCache instance using dependency injection. For example, to retrieve the cache from a Web API controller:

private readonly IDistributedCache _cache;

public ProductsController(IDistributedCache cache)
{
    _cache = cache;
}

When using .NET 9.0 or later, you can register a HybridCache which caches both locally and in Couchbase. This also registers IDistributedCache and ICouchbaseCache.

builder.AddCouchbaseHybridCache("couchbase");

Configuration

The Aspire Couchbase component offers various options for configuring the database connection according to your project's requirements and conventions.

Use a connection string

When using a connection string from the ConnectionStrings configuration section, you can provide the name of the connection string as the parameter when calling AddCouchbaseDistributedCache:

builder.AddCouchbaseDistributedCache("myConnection");

And then the connection string will be retrieved from the ConnectionStrings configuration section:

{
  "ConnectionStrings": {
    "myConnection": "couchbases://username:password@server1:11207,server2:11207/mybucket?option1=value1&option2=value2"
  }
}

See the ConnectionString documentation for more information on how to format this connection string. Couchbase.Aspire.Client extends the standard connection string format by allowing the inclusion of the username, password, and bucket name directly in the connection string.

Use configuration providers

The Aspire Couchbase Distributed Cache component supports Microsoft.Extensions.Configuration. It loads the CouchbaseClientSettings from configuration by using the Aspire:Couchbase:Client key. Example appsettings.json that configures some of the options:

{
  "Aspire": {
    "Couchbase": {
      "Client": {
        "ConnectionString": "couchbases://server:port",
        "Username": "username",
        "Password": "password",
        "BucketName": "cache", // Optional bucket name
        "DisableHealthChecks": false,
        "DisableTracing": false,
        "HealthChecks": {
          "Type": "Active",
          "MinimumHealthyNodes": {
            "KeyValue": 2,
            "Query": 2
          },
          "MaximumUnhealthyNodes": {
            "KeyValue": 0,
            "Query": 1
          }
        }
      }
    }
  }
}

Use inline delegates

You can also pass the Action<CouchbaseClientSettings> delegate to set up some or all of the options inline:

    builder.AddCouchbaseDistributedCache("couchbase",
        settings => settings.ConnectionString = "couchbases://server:port");

Further tuning of ClusterOptions can be done by passing an additional Action<ClusterOptions> delegate:

    builder.AddCouchbaseDistributedCache("couchbase",
        settings => settings.ConnectionString = "couchbases://server:port",
        options => options.WithSerializer(SystemTextJsonSerializer.Create());

AppHost extensions

In your AppHost project, install the Couchbase.Aspire.Hosting library with NuGet:

dotnet add package Couchbase.Aspire.Hosting

Then, in the AppHost.cs file of your project, register a Couchbase cluster and consume the connection using the following methods:

var couchbase = builder.AddCouchbase("couchbase");
var cache = couchbase.AddBucket("cache")
    .WithBucketType(BucketType.Ephemeral);

var myService = builder.AddProject<Projects.MyService>()
    .WithReference(cache)
    .WaitFor(cache);

The WithReference method configures a connection to a bucket in the MyService project named cache. In the Program.cs file of MyService, the database connection can be consumed using:

builder.AddCouchbaseDistributedCache("cache");

Additional documentation

Feedback & contributing

https://github.com/couchbaselabs/couchbase-aspire

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0-alpha.4 38 1/25/2026