-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Goals
- Improve cache performance and reduce cloud cost.
- Keep flexible invalidation when backend data changes.
- Preserve cache diagnostics headers:
X-Cache-Status,X-Cache-Key,X-Cache-Duration-Ms. - Keep hash vs raw cache key display configurable, and allow invalidation with either.
Target Design
Configuration (WebApi)
- Add EasyCaching packages (Memory + Redis).
- Configure in
Program.cs:AddEasyCaching(options => ...)- Choose providers via appsettings: memory only, redis only, or hybrid.
- Keep
Caching:Diagnosticssettings to control headers and key display mode.
Caching API
- Wrap EasyCaching with a small adapter to match current usage:
GetAsync<T>(key)SetAsync<T>(key, ttl)RemoveAsync(key)RemoveByPrefixAsync(prefix)orRemoveByTagAsync(tag)
- Prefer tags for invalidation:
- Tag all Employees responses with
Employees:GetAll - Tag all Positions responses with
Positions:GetAll
- Tag all Employees responses with
Diagnostics Headers
- Keep a thin diagnostics publisher:
- Emits
X-Cache-Status,X-Cache-Key,X-Cache-Duration-Ms. - Uses
Caching:Diagnosticssettings. - Supports
KeyDisplayMode: Raw|Hashwith hash invalidation mapping.
- Emits
Implementation Steps
- Add EasyCaching packages to WebApi (and Redis provider if distributed).
- Add EasyCaching configuration section to appsettings:
- Provider selection
- Redis connection string
- Build an adapter around EasyCaching:
- Map existing cache keys and prefixes/tags
- Track keys for hashed invalidation
- Replace current caching behaviors with EasyCaching adapter calls.
- Update invalidation endpoint to use tags/prefixes and hash mapping.
- Remove custom caching project/code and references.
- Update docs/tests to match new behavior.
Verification
- Hit
GET /api/v1/Employeestwice: expect MISS then HIT. - Confirm headers match config names.
- Invalidate by tag/prefix and verify next request is MISS.
- Test hash invalidation when
KeyDisplayMode=Hash.
Metadata
Metadata
Assignees
Labels
No labels