DeltaCore.CacheHelper 1.0.2

dotnet add package DeltaCore.CacheHelper --version 1.0.2
                    
NuGet\Install-Package DeltaCore.CacheHelper -Version 1.0.2
                    
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="DeltaCore.CacheHelper" Version="1.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DeltaCore.CacheHelper" Version="1.0.2" />
                    
Directory.Packages.props
<PackageReference Include="DeltaCore.CacheHelper" />
                    
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 DeltaCore.CacheHelper --version 1.0.2
                    
#r "nuget: DeltaCore.CacheHelper, 1.0.2"
                    
#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 DeltaCore.CacheHelper@1.0.2
                    
#: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=DeltaCore.CacheHelper&version=1.0.2
                    
Install as a Cake Addin
#tool nuget:?package=DeltaCore.CacheHelper&version=1.0.2
                    
Install as a Cake Tool

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

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.

Version Downloads Last Updated
1.0.2 219 4/25/2025
1.0.1 115 4/25/2025
1.0.0 168 4/23/2025