Appearance
Caching in JASE
JASE provides two in-process memory cache implementations:
Cache– static facade overInMemoryCacheSlidingCache<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
MemoryCachesemantics - 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
maxEntriesbound - Approximate LRU eviction
- Opportunistic pruning
- Optional eviction callback
- Automatic
IDisposablehandling
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
| Feature | Cache | SlidingCache |
|---|---|---|
| Static global | ✔ | ✖ |
| Instance-based | ✖ | ✔ |
| Absolute expiration | ✔ | ✖ |
| Sliding expiration | ✔ | ✔ |
| Approximate LRU | MemoryCache-managed | ✔ (queue-based) |
| Strict max entries | Optional | ✔ |
| File-based invalidation | ✔ | ✖ |
| Async factory support | ✔ | ✖ (sync only) |
| Eviction callback | Limited (MemoryCache style) | ✔ |
| Disposal ownership control | Partial | ✔ |
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).