Hk.RedisCache
0.1.0
dotnet add package Hk.RedisCache --version 0.1.0
NuGet\Install-Package Hk.RedisCache -Version 0.1.0
<PackageReference Include="Hk.RedisCache" Version="0.1.0" />
<PackageVersion Include="Hk.RedisCache" Version="0.1.0" />
<PackageReference Include="Hk.RedisCache" />
paket add Hk.RedisCache --version 0.1.0
#r "nuget: Hk.RedisCache, 0.1.0"
#:package Hk.RedisCache@0.1.0
#addin nuget:?package=Hk.RedisCache&version=0.1.0
#tool nuget:?package=Hk.RedisCache&version=0.1.0
Project Description
Easy usage & cleaner code with cache related code.
This project aims developers who use Redis as Cache Server. Provides easy API response cache, Entity/complex object cache, simple cache structure for developers.
It is simply a wrapper for Stackexchange.Redis and AspNetCore Service & ActionFilter.
Overview
This package can help caching responses and complex object cleaner! Here is simple example:
[HttpGet]
[RedisResponseCache]
public ActionResult<IEnumerable<string>> Get()
{
return new[] { "value1", "value2" };
}
This example shows how easily response cache with Redis.
You can easily use this feature. Just need add to AspNetCore Services.
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
//Order not important
services.AddMvc();
services.AddHkRedisCache(new HkRedisOptions
{
ConnectionString = "localhost:6379",
DatabaseId = 1,
Timeout = TimeSpan.FromHours(1) //(default value of cache timeout)
});
}
}
Also it provides complex object caching.
[HttpGet("{id}")]
public async Task<IActionResult> Get([FromRoute] int id)
{
var data = _cacheManager.Get<Customer>($"{nameof(Customer)}:{id}");
if(data == null)
return Ok(_context.Customers.FirstOrDefault(x => x.Id == id));
else
return Ok(data);
}
Instead of this code you can use easily example down below.
[HttpGet("{id}")]
public async Task<IActionResult> Get([FromRoute] int id)
{
var result = _cacheManager.GetFromCacheOrRun($"{nameof(Customer)}:{id}", () => { return _context.Customers.FirstOrDefault(x => x.Id == id); });
return Ok(result);
}
This simple usage cache any function response. It is useful for DAL return caching. You can use for every function! (Except void)
Also provides simple caching with Cache Manager object (ICacheManager)
public class CustomerController : ControllerBase
{
private readonly ICacheManager _cacheManager;
private readonly ApplicationDbContext _context;
public CustomerController(ICacheManager cacheManager, ApplicationDbContext context)
{
_cacheManager = cacheManager;
_context = context;
}
[HttpGet("cache/{id}")]
public async Task<IActionResult> GetFromCache([FromRoute]int id)
{
var result = _context.Customers.FirstOrDefault(x => x.Id == id);
_cacheManager.SetCache(result);
return Ok(result);
}
Also have some overload for simple usage
_cacheManager.SetCache(customerObject);
_cacheManager.SetCache("RedisKey",customerObject);
_cacheManager.SetCache("RedisKey",stringObject);
Cache Keys for objects
public class Customer
{
public int Id { get; set; }
public string Name { get; set; }
}
var customer = new Customer(){Id = 1, Name="Orhun"}
_cacheManager.SetCache(customerObject);
//key will be "Customer:1_Orhun"
Cache Keys will be every value with "_" (underscore) seperated. ":" (colon) for Redis default foldering mark.
Build
Install Visual Studio 2017 & .Net Core 2.1+ and run!
build.ps1
Who uses this package?
Hesapkurdu.com R&D team using at production!
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. 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. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.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
- JetBrains.Annotations (>= 2019.1.1)
- Microsoft.AspNetCore.Http.Abstractions (>= 2.1.1)
- Microsoft.AspNetCore.Http.Features (>= 2.1.1)
- Microsoft.AspNetCore.Mvc.Core (>= 2.1.1)
- Microsoft.AspNetCore.ResponseCaching (>= 2.1.1)
- Microsoft.Extensions.Configuration.Abstractions (>= 2.1.1)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 2.1.1)
- Microsoft.Extensions.Options (>= 2.1.1)
- Newtonsoft.Json (>= 12.0.1)
- StackExchange.Redis (>= 2.0.600)
- System.Collections (>= 4.3.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last Updated |
---|