CWA.DistributedCache
1.0.1
dotnet add package CWA.DistributedCache --version 1.0.1
NuGet\Install-Package CWA.DistributedCache -Version 1.0.1
<PackageReference Include="CWA.DistributedCache" Version="1.0.1" />
paket add CWA.DistributedCache --version 1.0.1
#r "nuget: CWA.DistributedCache, 1.0.1"
// 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 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 | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | 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.1
- Microsoft.Extensions.Caching.Memory (>= 6.0.0)
- Microsoft.Extensions.Caching.StackExchangeRedis (>= 6.0.1)
- Microsoft.Extensions.Configuration.Binder (>= 6.0.0)
- Microsoft.Extensions.Hosting.Abstractions (>= 6.0.0)
- System.Text.Json (>= 6.0.1)
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 | 667 | 1/30/2022 |