Athena.Cache.Redis 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Athena.Cache.Redis --version 1.0.0
                    
NuGet\Install-Package Athena.Cache.Redis -Version 1.0.0
                    
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="Athena.Cache.Redis" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Athena.Cache.Redis" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Athena.Cache.Redis" />
                    
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 Athena.Cache.Redis --version 1.0.0
                    
#r "nuget: Athena.Cache.Redis, 1.0.0"
                    
#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 Athena.Cache.Redis@1.0.0
                    
#: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=Athena.Cache.Redis&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Athena.Cache.Redis&version=1.0.0
                    
Install as a Cake Tool

๐Ÿ›๏ธ Athena.Cache

CI NuGet Core NuGet Redis License: MIT

Smart caching library for ASP.NET Core with automatic query parameter key generation and table-based cache invalidation.

Athena.Cache๋Š” ASP.NET Core ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ์œ„ํ•œ ์ง€๋Šฅํ˜• ์บ์‹ฑ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์ž…๋‹ˆ๋‹ค. ์ฟผ๋ฆฌ ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ์ž๋™์œผ๋กœ ์บ์‹œ ํ‚ค๋กœ ๋ณ€ํ™˜ํ•˜๊ณ , ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ํ…Œ์ด๋ธ” ๋ณ€๊ฒฝ ์‹œ ๊ด€๋ จ ์บ์‹œ๋ฅผ ์ž๋™์œผ๋กœ ๋ฌดํšจํ™”ํ•ฉ๋‹ˆ๋‹ค.

โœจ ์ฃผ์š” ๊ธฐ๋Šฅ

- ๐Ÿ”‘ **์ž๋™ ์บ์‹œ ํ‚ค ์ƒ์„ฑ**: ์ฟผ๋ฆฌ ํŒŒ๋ผ๋ฏธํ„ฐ โ†’ SHA256 ํ•ด์‹œ ํ‚ค ์ž๋™ ๋ณ€ํ™˜
- ๐Ÿ—‚๏ธ **ํ…Œ์ด๋ธ” ๊ธฐ๋ฐ˜ ๋ฌดํšจํ™”**: ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ํ…Œ์ด๋ธ” ๋ณ€๊ฒฝ ์‹œ ๊ด€๋ จ ์บ์‹œ ์ž๋™ ์‚ญ์ œ
- ๐Ÿš€ **๋‹ค์ค‘ ๋ฐฑ์—”๋“œ ์ง€์›**: MemoryCache, Redis, Valkey ์ง€์›
- ๐ŸŽฏ **์„ ์–ธ์  ์บ์‹ฑ**: `[AthenaCache]`, `[CacheInvalidateOn]` ์–ดํŠธ๋ฆฌ๋ทฐํŠธ
- โšก **๊ณ ์„ฑ๋Šฅ**: ๋Œ€์šฉ๋Ÿ‰ ํŠธ๋ž˜ํ”ฝ ํ™˜๊ฒฝ์— ์ตœ์ ํ™”
- ๐Ÿ”ง **์‰ฌ์šด ํ†ตํ•ฉ**: ๋ฏธ๋“ค์›จ์–ด์™€ ์•ก์…˜ ํ•„ํ„ฐ๋กœ ๊ฐ„๋‹จํ•œ ์„ค์ •
- ๐Ÿงช **์™„์ „ํ•œ ํ…Œ์ŠคํŠธ**: ํฌ๊ด„์ ์ธ ๋‹จ์œ„ ๋ฐ ํ†ตํ•ฉ ํ…Œ์ŠคํŠธ

๐Ÿš€ ๋น ๋ฅธ ์‹œ์ž‘

์„ค์น˜

# ๊ธฐ๋ณธ ํŒจํ‚ค์ง€ (MemoryCache ํฌํ•จ)
    dotnet add package Athena.Cache.Core

# Redis ์ง€์›
    dotnet add package Athena.Cache.Redis

๊ธฐ๋ณธ ์„ค์ •

// Program.cs
using Athena.Cache.Core.Extensions;

// ๊ฐœ๋ฐœ ํ™˜๊ฒฝ (MemoryCache)
services.AddAthenaCacheComplete(options => {
    options.Namespace = "MyApp_DEV";
    options.DefaultExpirationMinutes = 30;
});

// ์šด์˜ ํ™˜๊ฒฝ (Redis)
services.AddAthenaCacheRedisComplete(
    athena => {
        athena.Namespace = "MyApp_PROD";
        athena.DefaultExpirationMinutes = 60;
    },
    redis => {
        redis.ConnectionString = "localhost:6379";
        redis.DatabaseId = 1;
    });

// ๋ฏธ๋“ค์›จ์–ด ์ถ”๊ฐ€
app.UseAthenaCache();

์ปจํŠธ๋กค๋Ÿฌ์—์„œ ์‚ฌ์šฉ

[ApiController]
[Route("api/[controller]")]
public class UsersController : ControllerBase
{
    [HttpGet]
    [AthenaCache(ExpirationMinutes = 30)]
    [CacheInvalidateOn("Users")]
    public async Task<IActionResult> GetUsers(
        [FromQuery] string? search = null,
        [FromQuery] int page = 1)
    {
        // ๋น„์ฆˆ๋‹ˆ์Šค ๋กœ์ง
        // ์ฟผ๋ฆฌ ํŒŒ๋ผ๋ฏธํ„ฐ๋กœ๋ถ€ํ„ฐ ์บ์‹œ ํ‚ค ์ž๋™ ์ƒ์„ฑ๋จ
        var users = await _userService.GetUsersAsync(search, page);
        return Ok(users);
    }

    [HttpPost]
    public async Task<IActionResult> CreateUser([FromBody] User user)
    {
        var createdUser = await _userService.CreateUserAsync(user);
        // Users ํ…Œ์ด๋ธ” ๊ด€๋ จ ์บ์‹œ ์ž๋™ ๋ฌดํšจํ™”๋จ
        return CreatedAtAction(nameof(GetUser), new { id = createdUser.Id }, createdUser);
    }

    [HttpGet("{id}")]
    [AthenaCache(ExpirationMinutes = 60)]
    [CacheInvalidateOn("Users")]
    [CacheInvalidateOn("Orders", InvalidationType.Pattern, "User_*")]
    public async Task<IActionResult> GetUser(int id)
    {
        var user = await _userService.GetUserByIdAsync(id);
        if (user == null) return NotFound();
        return Ok(user);
    }
}

๐Ÿ› ๏ธ ๊ณ ๊ธ‰ ๊ธฐ๋Šฅ

์ปค์Šคํ…€ ์บ์‹œ ํ‚ค

[AthenaCache(
    ExpirationMinutes = 45,
    CustomKeyPrefix = "UserStats",
    ExcludeParameters = new[] { "debug", "trace" }
)]
public async Task<IActionResult> GetUserStatistics(int userId, bool debug = false)
{
    // debug ํŒŒ๋ผ๋ฏธํ„ฐ๋Š” ์บ์‹œ ํ‚ค ์ƒ์„ฑ์—์„œ ์ œ์™ธ๋จ
    return Ok(stats);
}

ํŒจํ„ด ๊ธฐ๋ฐ˜ ๋ฌดํšจํ™”

[CacheInvalidateOn("Users", InvalidationType.All)]                      // ๋ชจ๋“  Users ๊ด€๋ จ ์บ์‹œ
[CacheInvalidateOn("Orders", InvalidationType.Pattern, "User_*")]       // User_* ํŒจํ„ด ์บ์‹œ
[CacheInvalidateOn("Products", InvalidationType.Related, "Categories")] // ์—ฐ๊ด€ ํ…Œ์ด๋ธ”๊นŒ์ง€
public async Task<IActionResult> GetUserOrders(int userId) { ... }

์ˆ˜๋™ ์บ์‹œ ๊ด€๋ฆฌ

public class UserService
{
    private readonly IAthenaCache _cache;
    private readonly ICacheInvalidator _invalidator;

    public UserService(IAthenaCache cache, ICacheInvalidator invalidator)
    {
        _cache = cache;
        _invalidator = invalidator;
    }

    public async Task InvalidateUserCaches(int userId)
    {
        // ํŠน์ • ์‚ฌ์šฉ์ž ๊ด€๋ จ ์บ์‹œ๋งŒ ์‚ญ์ œ
        await _invalidator.InvalidateByPatternAsync($"User_{userId}_*");
    }

    public async Task<CacheStatistics> GetCacheStats()
    {
        return await _cache.GetStatisticsAsync();
    }
}

๐Ÿ“Š ์„ฑ๋Šฅ

  • ๋†’์€ ์ฒ˜๋ฆฌ๋Ÿ‰: Redis ๊ธฐ์ค€ 10,000+ requests/second
  • ๋‚ฎ์€ ์ง€์—ฐ์‹œ๊ฐ„: ์บ์‹œ ํ‚ค ์ƒ์„ฑ 1ms ๋ฏธ๋งŒ
  • ๋ฉ”๋ชจ๋ฆฌ ํšจ์œจ์„ฑ: ์ตœ์ ํ™”๋œ ์ง๋ ฌํ™” ๋ฐ ์••์ถ•
  • ํ™•์žฅ ๊ฐ€๋Šฅ: ๋‹ค์ค‘ ์ธ์Šคํ„ด์Šค ๋ถ„์‚ฐ ๋ฌดํšจํ™” ์ง€์›

๐Ÿ”ง ์„ค์ • ์˜ต์…˜

์ „์—ญ ์„ค์ •

services.AddAthenaCacheComplete(options => {
    options.Namespace = "MyApp";              // ๋„ค์ž„์ŠคํŽ˜์ด์Šค (ํ™˜๊ฒฝ ๋ถ„๋ฆฌ)
    options.VersionKey = "v1.0";              // ๋ฒ„์ „ ํ‚ค (๋ฐฐํฌ ์‹œ ์บ์‹œ ๋ถ„๋ฆฌ)
    options.DefaultExpirationMinutes = 30;    // ๊ธฐ๋ณธ ๋งŒ๋ฃŒ ์‹œ๊ฐ„
    options.MaxRelatedDepth = 3;              // ์—ฐ์‡„ ๋ฌดํšจํ™” ์ตœ๋Œ€ ๊นŠ์ด
    options.StartupCacheCleanup = CleanupMode.ExpireShorten; // ์‹œ์ž‘ ์‹œ ์ •๋ฆฌ ๋ฐฉ์‹
    
    // ๋กœ๊น… ์„ค์ •
    options.Logging.LogCacheHitMiss = true;   // ํžˆํŠธ/๋ฏธ์Šค ๋กœ๊น…
    options.Logging.LogInvalidation = true;   // ๋ฌดํšจํ™” ๋กœ๊น…
    
    // ์—๋Ÿฌ ์ฒ˜๋ฆฌ
    options.ErrorHandling.SilentFallback = true; // ์กฐ์šฉํ•œ ํด๋ฐฑ
});

Redis ์„ค์ •

services.AddAthenaCacheRedisComplete(
    athena => { /* Athena ์„ค์ • */ },
    redis => {
        redis.ConnectionString = "localhost:6379";
        redis.DatabaseId = 1;
        redis.KeyPrefix = "MyApp";
        redis.BatchSize = 1000;
        redis.ConnectTimeoutSeconds = 5;
        redis.RetryCount = 3;
    });

๐Ÿงช ํ…Œ์ŠคํŠธ

# ๋ชจ๋“  ํ…Œ์ŠคํŠธ ์‹คํ–‰
dotnet test

# ์ปค๋ฒ„๋ฆฌ์ง€ ํฌํ•จ
dotnet test --collect:"XPlat Code Coverage"

# ํ†ตํ•ฉ ํ…Œ์ŠคํŠธ (Redis ํ•„์š”)
docker run -d -p 6379:6379 redis:7-alpine
dotnet test --filter Category=Integration

๐Ÿ“– ์ถ”๊ฐ€ ๋ฌธ์„œ

๐Ÿ—๏ธ ์•„ํ‚คํ…์ฒ˜

ํ•ต์‹ฌ ์ปดํฌ๋„ŒํŠธ

  • ICacheKeyGenerator: ์ฟผ๋ฆฌ ํŒŒ๋ผ๋ฏธํ„ฐ โ†’ ์บ์‹œ ํ‚ค ๋ณ€ํ™˜
  • ICacheInvalidator: ํ…Œ์ด๋ธ” ๊ธฐ๋ฐ˜ ์บ์‹œ ๋ฌดํšจํ™” ๊ด€๋ฆฌ
  • IAthenaCache: ์บ์‹œ ์ œ๊ณต์ž ์ถ”์ƒํ™” (Memory/Redis/Valkey)
  • AthenaCacheMiddleware: HTTP ์š”์ฒญ ๊ฐ€๋กœ์ฑ„๊ธฐ ๋ฐ ์บ์‹ฑ
  • AthenaCacheActionFilter: ์–ดํŠธ๋ฆฌ๋ทฐํŠธ ๋ฉ”ํƒ€๋ฐ์ดํ„ฐ ์ˆ˜์ง‘

๋™์ž‘ ์›๋ฆฌ

  1. ์š”์ฒญ ๊ฐ€๋กœ์ฑ„๊ธฐ: ๋ฏธ๋“ค์›จ์–ด๊ฐ€ GET ์š”์ฒญ์„ ๊ฐ€๋กœ์ฑ”
  2. ํ‚ค ์ƒ์„ฑ: ์ฟผ๋ฆฌ ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ์ •๋ ฌํ•˜์—ฌ SHA256 ํ•ด์‹œ ์ƒ์„ฑ
  3. ์บ์‹œ ํ™•์ธ: ์ƒ์„ฑ๋œ ํ‚ค๋กœ ์บ์‹œ์—์„œ ์‘๋‹ต ์กฐํšŒ
  4. ์‘๋‹ต ์บ์‹ฑ: ์บ์‹œ ๋ฏธ์Šค ์‹œ ์‘๋‹ต์„ ์บ์‹œ์— ์ €์žฅ
  5. ๋ฌดํšจํ™”: ํ…Œ์ด๋ธ” ๋ณ€๊ฒฝ ์‹œ ๊ด€๋ จ ์บ์‹œ ์ž๋™ ์‚ญ์ œ

๐Ÿ”„ ์บ์‹œ ๋ฌดํšจํ™” ์ „๋žต

1. ์ฆ‰์‹œ ๋ฌดํšจํ™” (Immediate)

[CacheInvalidateOn("Users", InvalidationType.All)]

2. ํŒจํ„ด ๋ฌดํšจํ™” (Pattern-based)

[CacheInvalidateOn("Users", InvalidationType.Pattern, "User_*")]
[CacheInvalidateOn("Users", InvalidationType.Related, "Orders", "Profiles")]

๐Ÿค ๊ธฐ์—ฌํ•˜๊ธฐ

  1. ์ €์žฅ์†Œ ํฌํฌ
  2. ๊ธฐ๋Šฅ ๋ธŒ๋žœ์น˜ ์ƒ์„ฑ (git checkout -b feature/amazing-feature)
  3. ๋ณ€๊ฒฝ์‚ฌํ•ญ ์ปค๋ฐ‹ (git commit -m 'Add amazing feature')
  4. ๋ธŒ๋žœ์น˜์— ํ‘ธ์‹œ (git push origin feature/amazing-feature)
  5. Pull Request ์˜คํ”ˆ

๊ฐœ๋ฐœ ํ™˜๊ฒฝ ์„ค์ •

git clone https://github.com/jhbrunoK/Athena.Cache.git
cd Athena.Cache
dotnet restore
dotnet build
dotnet test

๐Ÿ“ ๋ผ์ด์„ผ์Šค

์ด ํ”„๋กœ์ ํŠธ๋Š” MIT ๋ผ์ด์„ผ์Šค ํ•˜์— ๋ฐฐํฌ๋ฉ๋‹ˆ๋‹ค. ์ž์„ธํ•œ ๋‚ด์šฉ์€ LICENSE ํŒŒ์ผ์„ ์ฐธ์กฐํ•˜์„ธ์š”.

๐Ÿ™ ๊ฐ์‚ฌ์˜ ๋ง

  • ์ „๋žต๊ณผ ์ง€ํ˜œ์˜ ์—ฌ์‹  ์•„ํ…Œ๋‚˜์—์„œ ์˜๊ฐ์„ ๋ฐ›์•˜์Šต๋‹ˆ๋‹ค
  • ASP.NET Core ์ปค๋ฎค๋‹ˆํ‹ฐ๋ฅผ ์œ„ํ•ด ์ œ์ž‘๋˜์—ˆ์Šต๋‹ˆ๋‹ค
  • ๋ชจ๋“  ๊ธฐ์—ฌ์ž๋ถ„๋“ค๊ป˜ ๊ฐ์‚ฌ๋“œ๋ฆฝ๋‹ˆ๋‹ค

๐Ÿ“ž ์ง€์› ๋ฐ ๋ฌธ์˜

  • ๐Ÿ› ๋ฒ„๊ทธ ๋ฆฌํฌํŠธ: GitHub Issues
  • ๐Ÿ’ก ๊ธฐ๋Šฅ ์š”์ฒญ: GitHub Discussions
  • ๐Ÿ“ง ์ด๋ฉ”์ผ: bobhappy2000@gmail.com

โค๏ธ ๊ณ ์„ฑ๋Šฅ ASP.NET Core ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ์œ„ํ•ด ์ œ์ž‘๋˜์—ˆ์Šต๋‹ˆ๋‹ค

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

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.1.9 53 8/2/2025
1.1.6 104 7/27/2025
1.1.5 90 7/27/2025
1.1.3 94 7/27/2025
1.1.2 92 7/27/2025
1.0.0 443 7/24/2025