feat: implement caching for user admission check#449
Open
Mohit-Davar wants to merge 1 commit intocameri:mainfrom
Open
feat: implement caching for user admission check#449Mohit-Davar wants to merge 1 commit intocameri:mainfrom
Mohit-Davar wants to merge 1 commit intocameri:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Implements Redis-backed caching for the EventMessageHandler.isUserAdmitted check to reduce repeated database lookups during high-throughput event ingestion.
Changes:
- Injected an
ICacheAdapterintoEventMessageHandlerand added cache read/write logic for admission decisions. - Introduced a Redis-backed cache singleton in
message-handler-factoryfor reuse across handlers. - Updated unit test constructions of
EventMessageHandlerto pass a cache adapter stub.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/handlers/event-message-handler.ts |
Adds Redis cache read/write paths and a helper for non-blocking cache writes in isUserAdmitted. |
src/factories/message-handler-factory.ts |
Creates/reuses a Redis cache adapter instance and injects it into EventMessageHandler. |
test/unit/handlers/event-message-handler.spec.ts |
Updates handler instantiation to include the new cache dependency. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
81e8d30 to
40bcf16
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR implements the
TODO: use cacheinEventMessageHandlerby introducing a Redis-based caching layer for user admission status.Key Implementation Details
State-Aware Caching
getKeyto differentiate:1→ Admitted users0→ Blocked / insufficient balancenull→ Cache missTTL Strategy
Atomicity & Resilience
cacheSethelperTesting
event-message-handler.spec.tswith mock cache behaviorRelated Issue
Resolves the caching TODO in:
src/handlers/event-message-handler.ts#447
Motivation and Context
On high-traffic relays, performing database checks for every event introduces significant overhead.
This change:
How Has This Been Tested?
test/unit/handlers/event-message-handler.spec.tsScreenshots
N/A
Types of Changes
Checklist