Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@zto-sbenning
Copy link
Contributor

…ion context

  • Add SetContext type with isInitialHydration flag
  • Update Handler interface to accept optional SetContext in set()
  • Implement NX behavior in redis-strings handler when isInitialHydration is true
  • Update all handlers (local-lru, composite) to accept ctx parameter
  • Propagate isInitialHydration flag from registerInitialCache to handlers
  • Prevents runtime cache overwrites during app restarts and horizontal scaling

Addresses #23

…ion context

- Add SetContext type with isInitialHydration flag
- Update Handler interface to accept optional SetContext in set()
- Implement NX behavior in redis-strings handler when isInitialHydration is true
- Update all handlers (local-lru, composite) to accept ctx parameter
- Propagate isInitialHydration flag from registerInitialCache to handlers
- Prevents runtime cache overwrites during app restarts and horizontal scaling

Addresses fortedigital#23
@zto-sbenning
Copy link
Contributor Author

Hi @AyronK,

I've implemented a solution for #23 . I'd really appreciate your thoughts on this implementation before marking it as ready for review.

Approach chosen

Instead of adding the option to registerInitialCache settings (as initially suggested), I followed your comment about preferring "config on redis handler or env variable" by implementing this at the handler level:

  • Added a new SetContext type with an isInitialHydration flag
  • Updated the Handler interface to accept optional context in set()
  • registerInitialCache passes isInitialHydration: true when hydrating
  • Redis handler uses NX option when this flag is set
  • All handlers updated to accept the context (backward compatible)

Happy to adjust anything - just wanted to get your feedback on the architecture first!

Copy link
Collaborator

@AyronK AyronK left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work overall, I added a couple of comments for cosmetics. However I really would like to make opt-in behavior with default as it was.

Also, could you update readme section of instrumentation / initial cache registration to mention this option?

Make non-destructive cache writes opt-in, improve naming, handler behavior, and documentation following review comments.
@zto-sbenning
Copy link
Contributor Author

Thanks for the review!

I’ve addressed all the comments:

  • made the non-overwriting behavior opt-in with default unchanged
  • renamed the flag to setOnlyIfNotExists to better reflect intent
  • aligned the LRU handler behavior without Redis-specific terminology
  • refactored the Redis set options
  • updated the README to document the initial cache write strategy

Please let me know if you’d like any further adjustments.

@zto-sbenning zto-sbenning marked this pull request as ready for review January 13, 2026 10:41
@zto-sbenning zto-sbenning requested a review from AyronK January 13, 2026 12:24
Copy link
Collaborator

@AyronK AyronK left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very solid PR now, thanks!

@AyronK AyronK merged commit 1e0f942 into fortedigital:master Jan 14, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants