Couchbase.Extensions.Caching
1.0.2
Prefix Reserved
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
<PackageReference Include="Couchbase.Extensions.Caching" Version="1.0.2" />
paket add Couchbase.Extensions.Caching --version 1.0.2
#r "nuget: Couchbase.Extensions.Caching, 1.0.2"
// 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 | Versions 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. |
-
.NETStandard 2.0
- Couchbase.Extensions.DependencyInjection (>= 1.0.0)
- CouchbaseNetClient (>= 2.6.0)
- Microsoft.Extensions.Caching.Abstractions (>= 2.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 2.0.0)
- Microsoft.Extensions.Options (>= 2.0.0)
- System.ComponentModel.TypeConverter (>= 4.3.0)
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.