Configurable Channel and Zone cache strategies #5247
rafabernad
started this conversation in
Feature Requests
Replies: 1 comment
|
A proposed implementation is now available in #5248. |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Proposal
Expose two configurable cache extension points:
ChannelCacheStrategyfor storing, resolving and invalidating individual Channels;ZoneCacheStrategyfor loading, storing and invalidating the Zone list.The default implementations use a short-lived process-local L1 and the globally configured
CacheStrategyas a longer-lived L2. Channel entries are keyed by token, include a dedicated default-Channel key and coalesce concurrent misses. Zone operations receive theRequestContextand a loader callback.Channel and Zone mutations update or invalidate both cache levels. Custom implementations can control cache behavior without changing
ChannelServiceorZoneService.CacheStrategy lifecycle
CacheServiceowns initialization and destruction of the globalCacheStrategy. Lazy single-flight initialization ensures that early cache access and the Nest lifecycle share one initialization attempt. Failed initialization can be retried, and teardown runs only after successful initialization.Compatibility
Both strategy properties are optional and have default implementations. No database schema or GraphQL API changes are required.
Performance
A compiled-code microbenchmark measured a hot L1 lookup at approximately 0.4 µs. With very small Channel counts, this adds approximately 0.1–0.2 µs relative to an array lookup; from roughly 100 cached Channels onward, the O(1) lookup is faster. An L2 hit using the in-memory
CacheStrategy, including deserialization and entity rehydration, measured approximately 4.2 µs.Pull request
Related work
All reactions