Skip to content

CachingService.getOrSet has no distributed locking causing thundering…#945

Open
heymide wants to merge 1 commit into
rinafcode:mainfrom
heymide:caching-service
Open

CachingService.getOrSet has no distributed locking causing thundering…#945
heymide wants to merge 1 commit into
rinafcode:mainfrom
heymide:caching-service

Conversation

@heymide

@heymide heymide commented Jun 29, 2026

Copy link
Copy Markdown

Close: #812
I've successfully fixed the thundering herd issue in CachingService.getOrSet ! Here's what was changed:

  1. Injected DistributedLockService into CachingService using the @optional() decorator, which allows graceful fallback to the old behavior if the lock service isn't available
  2. Modified getOrSet method :
    • Added lock key: lock:cache:{key}
    • Added configurable parameters: lockTimeoutMs , pollIntervalMs , maxWaitMs
    • On cache miss, tries to acquire a lock first
    • Lock holders: double-check cache, run factory, store result, then release lock
    • Non-lock holders: poll cache (with jitter) until either the result is available or timeout is reached
  3. Added a private sleep helper to handle polling delays

@drips-wave

drips-wave Bot commented Jun 29, 2026

Copy link
Copy Markdown

@heymide Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@heymide

heymide commented Jun 29, 2026

Copy link
Copy Markdown
Author

Done, Close: #945

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.

CachingService.getOrSet has no distributed locking causing thundering herd

1 participant