Couchbase.Extensions.Caching 4.0.0

Prefix Reserved
dotnet add package Couchbase.Extensions.Caching --version 4.0.0                
NuGet\Install-Package Couchbase.Extensions.Caching -Version 4.0.0                
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.Extensions.Caching" Version="4.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Couchbase.Extensions.Caching --version 4.0.0                
#r "nuget: Couchbase.Extensions.Caching, 4.0.0"                
#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.
// Install Couchbase.Extensions.Caching as a Cake Addin
#addin nuget:?package=Couchbase.Extensions.Caching&version=4.0.0

// Install Couchbase.Extensions.Caching as a Cake Tool
#tool nuget:?package=Couchbase.Extensions.Caching&version=4.0.0                

Couchbase Distributed Cache for ASP.NET Core

A custom ASP.NET Core Middleware plugin for a distributed cache using Couchbase server as the backing store. Supports both Ephemeral (in-memory) and Couchbase (persistent) buckets.

Getting Started

Assuming you have an installation of Couchbase Server and Visual Studio (examples with VSCODE forthcoming), do the following:

Couchbase .NET Core Distributed Cache

  • Create a .NET Core Web Application using Visual Studio or VsCodeor CIL
  • Install the package from NuGet or build from source and add reference

Setup

In Setup.cs add the following to the ConfigureServices method:

public void ConfigureServices(IServiceCollection services)
{
    // Add framework services.
    services.AddMvc();

    services.AddCouchbase(opt =>
    {
        opt.ConnectionString = "couchbase://localhost";
        opt.UserName = "Administrator";
        opt.Password = "password";
    });

    services.AddDistributedCouchbaseCache(opt => { 
        opt.BucketName = "cache";
        opt.ScopeName = "my_service";
        opt.CollectionName = "my_collection";
    });
}

You can change the localhost hostname to wherever you are hosting your Couchbase cluster.

Using Caching in your Controllers

In your controller add a parameter for ICouchbaseCache or IDistributedCache to the constructor. Using IDistributedCache will allow persistence of byte[] to the cache. ICouchbaseCache extends this functionality with additional methods for storing and retrieving typed objects.

public class HomeController : Controller
{
    private ICouchbaseCache _cache;

    public HomeController(ICouchbaseCache cache)
    {
        _cache = cache;
    }

    public async Task<IActionResult> Index()
    {
        await _cache.SetAsync("CacheTime", DateTimeOffset.Now);
        return View();
    }

    public IActionResult About()
    {
        ViewData["Message"] = "Your application description page. "
                    + (await _cache.GetAsync<DateTimeOffset>("CacheTime"));
        return View();
    }
}

For performance reasons, we strongly recommend using the Async overloads and not the synchronous methods on IDistributeCache.

Serialization and Transcoding

Any type you persist in the cache will be transcoded and serialized using the transcoder and serializer configured in the call to AddCouchbase. By default, this is the JsonTranscoder and the DefaultSerializer which uses Newtonsoft.Json. However, setting and getting byte[] is always transcoded as raw binary regardless of the configured transcoder.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  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 was computed.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Couchbase.Extensions.Caching:

Package Downloads
Couchbase.Extensions.Session

A custom ASP.NET Core Middleware plugin for distributed session state using Couchbase server as the backing store. Supports both Memcached (in-memory) and Couchbase (persistent) buckets.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
4.0.0 96 2/26/2025
3.3.5 126,276 9/19/2022
3.3.4 964 9/14/2022
3.2.5 149,765 12/17/2021
2.0.0-beta.2 324 9/15/2021
1.0.2 180,400 8/11/2018
1.0.1 5,674 3/1/2018
1.0.0 3,407 11/8/2017