Skip to content

Caching in JASE ​

JASE provides two in-process memory cache implementations:

  1. Cache – static facade over InMemoryCache
  2. SlidingCache<TKey, TValue> – bounded, approximate-LRU cache with sliding TTL

Both are thread-safe and intended for high-performance server scenarios, but they serve different use cases.


1. Cache (static facade) ​

Backed by: Microsoft.Extensions.Caching.Memory.MemoryCache
Best for: general-purpose application caching

Characteristics ​

  • Static, global instance
  • Supports:
    • Absolute expiration
    • Sliding expiration
    • File-based invalidation
    • Optional size-based eviction
    • Async read-through patterns
  • Optional copy-on-read safety
  • Tracks statistics (hits, attempts, evictions)

When to use ​

Use Cache when:

  • You want a simple, application-wide cache
  • You want file-based invalidation
  • You want integration with MemoryCache semantics
  • You want a low-friction drop-in cache

See: Cache


2. SlidingCache<TKey, TValue> ​

Custom implementation
Best for: high-control, bounded, sliding-only workloads

Characteristics ​

  • Generic, instance-based
  • Sliding expiration only
  • Strict maxEntries bound
  • Approximate LRU eviction
  • Opportunistic pruning
  • Optional eviction callback
  • Automatic IDisposable handling

When to use ​

Use SlidingCache<TKey,TValue> when:

  • You need hard size bounds
  • You want predictable sliding TTL behavior
  • You want to control eviction ownership
  • You do not need file watchers
  • You want zero dependency on MemoryCache

See: SlidingCache<TKey, TValue>


Comparison ​

FeatureCacheSlidingCache
Static global✔✖
Instance-based✖✔
Absolute expiration✔✖
Sliding expiration✔✔
Approximate LRUMemoryCache-managed✔ (queue-based)
Strict max entriesOptional✔
File-based invalidation✔✖
Async factory support✔✖ (sync only)
Eviction callbackLimited (MemoryCache style)✔
Disposal ownership controlPartial✔

Important Notes ​

  • Both caches are in-process only.
  • Neither is distributed.
  • Restarting the application clears all entries.
  • Sliding expiration uses monotonic tick count (Environment.TickCount64).