DeltaCore.CacheHelper
1.0.2
dotnet add package DeltaCore.CacheHelper --version 1.0.2
NuGet\Install-Package DeltaCore.CacheHelper -Version 1.0.2
<PackageReference Include="DeltaCore.CacheHelper" Version="1.0.2" />
<PackageVersion Include="DeltaCore.CacheHelper" Version="1.0.2" />
<PackageReference Include="DeltaCore.CacheHelper" />
paket add DeltaCore.CacheHelper --version 1.0.2
#r "nuget: DeltaCore.CacheHelper, 1.0.2"
#:package DeltaCore.CacheHelper@1.0.2
#addin nuget:?package=DeltaCore.CacheHelper&version=1.0.2
#tool nuget:?package=DeltaCore.CacheHelper&version=1.0.2
CacheHelper
DeltaCore.CacheHelper
DeltaCore.CacheHelper
is a lightweight .NET library designed to simplify caching operations in your .NET applications using either in-memory or distributed (Redis) cache mechanisms.
This library abstracts common caching patterns to help developers interact with caching in a clean, reusable, and testable manner.
Features
- In-Memory Caching using
IMemoryCache
- Distributed Caching using
IDistributedCache
(supports Redis) - Generic methods for
Get
,Set
, andDelete
- Overloaded
Set
methods to support custom expiration - Fully asynchronous for distributed cache
- Supports
SlidingExpiration
,AbsoluteExpiration
, and customizable options
Installation
Once published on NuGet, you’ll be able to install it using:
dotnet add package DeltaCore.CacheHelper
🚀 Usage
1. MemoryCacheService (In-Memory)
public class SomeService
{
private readonly MemoryCachService _cache;
public SomeService(MemoryCachService cache)
{
_cache = cache;
}
public void SetItem()
{
_cache.SetData<object>("user:1", new { Name = "Ahmed", Age = 21 });
}
public object? GetItem()
{
return _cache.GetData<object>("user:1");
}
public void RemoveItem()
{
_cache.DelData("user:1");
}
}
You can also pass custom expiration:
var options = new MemoryCacheEntryOptions().SetAbsoluteExpiration(TimeSpan.FromMinutes(15));
_cache.SetData<T>("key", <T>value, options);
2. RedisCacheService (Distributed)
public class SomeService
{
private readonly RedisCacheService _cache;
public SomeService(RedisCacheService cache)
{
_cache = cache;
}
public async Task SetAsync()
{
await _cache.SetDataAsync<object>("product:1", new { Id = 1, Name = "Bread" });
}
public async Task<object?> GetAsync()
{
return await _cache.GetDataAsync<object>("product:1");
}
public async Task DeleteAsync()
{
await _cache.DelDataAsync("product:1");
}
}
With custom expiration:
var options = new DistributedCacheEntryOptions
{
AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(30)
};
await _cache.SetDataAsync<T>("key", <T>value, options);
Configuration
Add Services in Program.cs
builder.Services.AddMemoryCache();
builder.Services.AddStackExchangeRedisCache(options =>
{
options.Configuration = builder.Configuration.GetConnectionString("Redis");
});
builder.Services.AddScoped<MemoryCachService>();
builder.Services.AddScoped<RedisCacheService>();
Project Structure
DeltaCore.CacheHelper/
├── MemoryCacheService.cs # Handles in-memory caching
├── RedisCacheService.cs # Handles distributed (Redis) caching
├── DeltaCore.CacheHelper.csproj
GitHub Actions (CI/CD)
This project includes a GitHub Action to automatically publish the package to NuGet when you push a tag in the format v*.*.*.
Workflow file:.github/workflows/nuget-publish.yml
License
This project is licensed under the MIT License.
Author
Created by Ahmed Nady
GitHub: AhmedNady2003
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. 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. |
-
net8.0
- Microsoft.Extensions.Caching.Memory (>= 9.0.4)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on DeltaCore.CacheHelper:
Package | Downloads |
---|---|
DeltaCore.EmailService
This is a NuGet package for DeltaCore Email Service, Send mail and otp and verify otp. |
GitHub repositories
This package is not used by any popular GitHub repositories.