Skip to content

Enhance thread-safety in ClientSideCaching key retrieval #3268

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

yybmion
Copy link

@yybmion yybmion commented Apr 20, 2025

Issue

Closes #2402

The current implementation of the get method in the ClientSideCaching class does not provide a mechanism to ensure exclusive access by a single thread when retrieving a value from the Redis server for a specific key. As a result, in high concurrent load scenarios involving the same key, the current implementation may cause redundant and unnecessary calls to the Redis server.

Solution

Added a per-key locking mechanism using ReentrantLock to ensure that only a single thread can fetch a value from Redis for a specific key at any given time.

Tests

  1. valueLoaderShouldBeInvokedOnceForConcurrentRequests: Verifies that when multiple threads concurrently access the same key using a valueLoader, the loader is called exactly once

  2. locksShouldBeProperlyCleanedUp: Verifies the proper lifecycle management of locks (creation, cleanup on invalidation, recreation, and final cleanup)

Added per-key locking mechanism to ensure that only a single thread
fetches a value from Redis cache for a specific key. This prevents
redundant Redis server calls under high concurrent load.
@yybmion yybmion changed the title Enhance thread-safety in ClientSideCaching key retrieval #2402 Enhance thread-safety in ClientSideCaching key retrieval Apr 20, 2025
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.

Client-Side Caching - Enhancing Thread-Safety in Key Retrieval
1 participant