Netcool.Caching
9.0.0
dotnet add package Netcool.Caching --version 9.0.0
NuGet\Install-Package Netcool.Caching -Version 9.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="Netcool.Caching" Version="9.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Netcool.Caching --version 9.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Netcool.Caching, 9.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 Netcool.Caching as a Cake Addin #addin nuget:?package=Netcool.Caching&version=9.0.0 // Install Netcool.Caching as a Cake Tool #tool nuget:?package=Netcool.Caching&version=9.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Netcool.Caching
Netcool.Caching offers enhanced extensions for Distributed caching in ASP.NET Core, both MemoryDistributeCache and RedisCache.
Configuration
Distributed Redis cache
builder.Services.AddNetcoolRedisCache(options =>
{
options.Configuration = "localhost";
});
Distributed Memory Cache
builder.Services.AddNetcoolDistributedMemoryCache();
Use in application service
public class MyService : IService
{
private readonly INetcoolDistributedCache _cache;
public MyService(INetcoolDistributedCache cache)
{
_cache = cache;
}
public void SetCache()
{
var obj = new WeatherForecast
{
Date = DateTime.Now,
TemperatureC = Random.Shared.Next(-20, 55),
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
};
_cache.SetObject("WeatherForecast", obj,
new DistributedCacheEntryOptions { AbsoluteExpiration = DateTimeOffset.Now.AddMinutes(5) });
}
}
Extensions
Set and get object
cache.SetObject("Person", new Person());
var person = cache.GetObject("Person");
await cache.SetObjectAsync("Person", new Person());
var person =await cache.GetObjectAsync("Person");
Increase and decrease
cache.SetString("count", "1");
var curr = cache.Increase("count",byValue:2, maxValue:10);
var curr2 = await cache.IncreaseAsync("count",2);
var res = cache.GetString("count");
Assert.AreEqual("3", res);
Assert.AreEqual(3, curr);
cache.SetString("count", "1");
var curr = cache.Decrease("count", byValue:2, minValue:1);
var curr2 = await cache.DecreaseAsync("count", byValue:2, minValue:1);
var res = cache.GetString("count");
Assert.AreEqual(1, curr);
Assert.AreEqual("1", res);
Object Serializer
The default object serializer is SystemTextJsonSerializer, you can change the JsonSerializerOptions.
builder.Services.AddNetcoolRedisCache(options =>
{
options.Configuration = "localhost";
options.ObjectSerializer = new SystemTextJsonSerializer(new JsonSerializerOptions());
});
Otherwise, you can customize your own serializer:
public class MySerializer : ISerializer
{
private readonly JsonSerializerOptions _jsonSerializerOptions;
public byte[] Serialize<T>(T obj)
{
return Encoding.UTF8.GetBytes(obj.ToString());
}
public T Deserialize<T>(byte[] bytes)
{
return (T)Convert.ChangeType(Encoding.UTF8.GetString(b).ToString(), typeof(T));
}
}
Then configure at startup:
builder.Services.AddNetcoolRedisCache(options =>
{
options.Configuration = "localhost";
options.ObjectSerializer = new MySerializer();
});
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 is compatible. |
.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.
-
.NETStandard 2.0
- Microsoft.Extensions.Caching.Memory (>= 9.0.0)
- Microsoft.Extensions.Caching.StackExchangeRedis (>= 9.0.0)
- System.Text.Json (>= 9.0.0)
-
.NETStandard 2.1
- Microsoft.Extensions.Caching.Memory (>= 9.0.0)
- Microsoft.Extensions.Caching.StackExchangeRedis (>= 9.0.0)
- System.Text.Json (>= 9.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Update nuget packages.