Couchbase.Extensions.Caching 1.0.2

Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package Couchbase.Extensions.Caching --version 1.0.2                
NuGet\Install-Package Couchbase.Extensions.Caching -Version 1.0.2                
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="1.0.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Couchbase.Extensions.Caching --version 1.0.2                
#r "nuget: Couchbase.Extensions.Caching, 1.0.2"                
#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=1.0.2

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

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 Memcached (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.Servers = new List<Uri>
            {
                new Uri("http://10.111.150.101:8091")
            };
        });

        services.AddDistributedCouchbaseCache("default", opt => { });
}

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

In your controller add a parameter for IDistributedCache to the constructor:

 public class HomeController : Controller
 {
	private IDistributedCache _cache;

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

Tear down

There are a couple different ways to free up the resources (TCP sockets, etc) opened by the Couchbase ICluster and IBucket used by the Distributed Session. Here is one simple way to tap into the ApplicationStopped cancellation token:

public void ConfigureServices(IServiceCollection services)
{
	...

 	applicationLifetime.ApplicationStopped.Register(() =>
    {
        app.ApplicationServices.GetRequiredService<ICouchbaseLifetimeService>().Close();
    });
}

Using Caching in your Controllers

Add the following code to HomeController:

public IActionResult Index()
{
	_cache.Set("CacheTime", System.Text.Encoding.UTF8.GetBytes(DateTime.Now.ToString()));
	return View();
}

public IActionResult About()
{
	ViewData["Message"] = "Your application description page. "
				+ System.Text.Encoding.UTF8.GetString(_cache.Get("CacheTime"));
	return View();
}
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos 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
3.3.5 108,242 9/19/2022
3.3.4 946 9/14/2022
3.2.5 146,547 12/17/2021
2.0.0-beta.2 311 9/15/2021
1.0.2 177,841 8/11/2018
1.0.1 5,524 3/1/2018
1.0.0 3,231 11/8/2017