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
<PackageReference Include="Couchbase.Extensions.Caching" Version="4.0.0" />
paket add Couchbase.Extensions.Caching --version 4.0.0
#r "nuget: Couchbase.Extensions.Caching, 4.0.0"
// 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 | Versions 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. |
-
net6.0
- Couchbase.Extensions.DependencyInjection (>= 3.6.5)
- CouchbaseNetClient (>= 3.6.5)
- Microsoft.Bcl.TimeProvider (>= 8.0.1)
- Microsoft.Extensions.Caching.Abstractions (>= 9.0.1)
-
net8.0
- Couchbase.Extensions.DependencyInjection (>= 3.6.5)
- CouchbaseNetClient (>= 3.6.5)
- Microsoft.Extensions.Caching.Abstractions (>= 9.0.1)
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.