Hk.RedisCache 0.1.0

The owner has unlisted this package. This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package Hk.RedisCache --version 0.1.0
                    
NuGet\Install-Package Hk.RedisCache -Version 0.1.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="Hk.RedisCache" Version="0.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Hk.RedisCache" Version="0.1.0" />
                    
Directory.Packages.props
<PackageReference Include="Hk.RedisCache" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Hk.RedisCache --version 0.1.0
                    
#r "nuget: Hk.RedisCache, 0.1.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.
#:package Hk.RedisCache@0.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Hk.RedisCache&version=0.1.0
                    
Install as a Cake Addin
#tool nuget:?package=Hk.RedisCache&version=0.1.0
                    
Install as a Cake Tool

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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