Skip to content
bitzorcas
EN

Reference

Caching building block

In-memory caching with IMemoryCache — idempotency deduplication, rate limiting counters, and future FusionCache roadmap for multi-tier caching.

Last updated

BitzOrcas currently uses IMemoryCache for single-instance in-memory caching needs. A multi-tier caching strategy with FusionCache is on the roadmap for production multi-instance deployments.

Current usage

Idempotency deduplication

The IdempotencyPipelineBehavior uses IMemoryCache to deduplicate requests carrying an Idempotency-Key header:

// Request with Idempotency-Key: "req-abc123"
// → First call: executes handler, caches result
// → Duplicate call: returns cached result immediately

Registered in ApiPipelineRegistration:

services.AddMemoryCache(); // Powers IdempotencyPipelineBehavior

Rate limiting counters

ASP.NET Core’s built-in RateLimiter uses in-memory partitioned counters. See Web building block for policy details.

Roadmap: FusionCache

Planned multi-tier caching with FusionCache:

┌───────────────────────────────────────┐
│ Application Layer │
│ Cache Get/Set │
└───────────────┬───────────────────────┘
┌───────────────────────────────────────┐
│ FusionCache │
│ ┌─────────────┐ ┌───────────────┐ │
│ │ L1 Memory │ │ L2 Redis/ │ │
│ │ (local) │→ │ Distributed │ │
│ └─────────────┘ └───────────────┘ │
│ + Stampede protection │
│ + Fail-safe fallback │
│ + OpenTelemetry instrumentation │
└───────────────────────────────────────┘

Planned features

  • L1/L2 cache tier — in-process memory + distributed (Redis/Valkey)
  • Stampede protection — prevent cache thundering herd
  • Fail-safe — graceful fallback when L2 is unavailable
  • OTel instrumentation — cache hit/miss metrics
  • Cache key versioning — automatic invalidation on schema changes

Configuration (future)

{
"FusionCache": {
"L1Enabled": true,
"L2Enabled": true,
"L2ConnectionString": "localhost:6379",
"DefaultDuration": "00:05:00",
"MaximumDuration": "01:00:00"
}
}