CWA.DistributedCache 1.0.1

.NET Standard 2.1
NuGet\Install-Package CWA.DistributedCache -Version 1.0.1
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.
dotnet add package CWA.DistributedCache --version 1.0.1
<PackageReference Include="CWA.DistributedCache" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add CWA.DistributedCache --version 1.0.1
#r "nuget: CWA.DistributedCache, 1.0.1"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install CWA.DistributedCache as a Cake Addin
#addin nuget:?package=CWA.DistributedCache&version=1.0.1

// Install CWA.DistributedCache as a Cake Tool
#tool nuget:?package=CWA.DistributedCache&version=1.0.1

CWA.DistributedCaching

A simple package to implement and extended the functionality of IDistributedCache interface (Memory, Redis) to make the caching more easier.

Prerequisites

Setting Up Redis

This step Creating a Redis docker container is if you are going to deal with redis caching, but if you are going to deal with memory caching you don't need it.

For this step, I assume that you have already installed Docker on your machine. It’s handy to have this so that you can spin up your own Redis container whenever you want for development purposes.

Creating a Redis docker container
docker run --name redis-cache -p 6379:6379 -d redis
By default, Redis runs on the local 6379 port , To change the port you can use this commend
docker run --name my-redis -p 5002:6379 -d redis

Installation

First install the latest version of CWA.DistributedCaching nuget package into your project as follows:

Install-Package CWA.DistributedCaching

Basic usage

    [HttpGet]
    public async Task<List<Customer>?> Get()
    {
        string cacheKey = CustomerCacheKeys.ListKey;
        List<Customer>? customerList = await _distributedCache.GetAsync<List<Customer>>(cacheKey);
        if (customerList == null)
        {
            customerList = await _repository.ListAllAsync();
            await _distributedCache.SetAsync(cacheKey, customerList, GetOptions()).ConfigureAwait(false);
        }
        return customerList;
    }

    [HttpPost]
    public async Task<ActionResult<Customer>> Post(Customer customer)
    {
        await _repository.AddAsync(customer);
        string cacheKey = CustomerCacheKeys.GetKey(customer.Id);
        await _distributedCache.SetAsync(cacheKey, customer, GetOptions()).ConfigureAwait(false);
    
        // Add customer to list
        string cacheKeyList = CustomerCacheKeys.ListKey;
        await _distributedCache
            .AddToListAsync<Customer, int>(cacheKeyList, customer,
                GetOptions());
    
        return customer;
    }

Bug(🐞) Report

Dont forget to submit an issue if you face. we will try to resolve as soon as possible.

Give a star (⭐)

If you find this library useful to you, please don't forget to encouraging me to do such more stuffs by giving a star (⭐) to this repository. Thank you.

Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows
.NET Core netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.1
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
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
1.0.1 98 1/30/2022