Skip to content

simoneM93/AspNetCoreCacheKit

Repository files navigation

AspNetCoreCacheKit

NuGet

A modern caching library for ASP.NET Core featuring group-based keys, configuration validation, and simplified overloads.

✨ Features

  • 🔑 Group-based keys ("users:123")
  • Optimized performance with GetOrCreate
  • Configuration validation with DataAnnotations
  • 📐 Nullable reference types support
  • 🎛️ appsettings.json configuration
  • 🧪 DI-ready Scoped service

📋 Requirements

Requirement Minimum Version
.NET 9.0+
ASP.NET Core 9.0+

🚀 Installation

dotnet add package AspNetCoreCacheKit

🎯 Quick Start

1. Configure appsettings.json

{
  "CacheOptions": {
    "IsEnabled": true,
    "Duration": 60 //Expressed in minutes
  }
}

2. Register Services

// With config
builder.Services.AddAspNetCoreCacheKit(builder.Configuration);

// Only defaults (Without appsettings)
builder.Services.AddAspNetCoreCacheKit();

3. Use in Controller/Service

[ApiController]
public class UsersController : ControllerBase
{
    private readonly ICacheService _cache;

    public UsersController(ICacheService cache)
    {
        _cache = cache;
    }

    [HttpGet]
    public async Task<IActionResult> GetUsers()
    {
        // With group
        var users = await _cache.GetOrCreateAsync("users", "all", GetUsersFromDb);
        
        // Without group (overload)
        var config = _cache.GetOrCreate("app:config", LoadConfig);
        
        return Ok(users);
    }
}

About

Lightweight, extensible caching toolkit for ASP.NET Core (.NET 9+) — providers, middleware and helpers for in-memory & distributed caching.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages