You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
mp911de
changed the title
Inefficient blocking method call for loading new/expired values?RedisCache.get(Object, Callable) synchronizes on entire cache instead of individual keys
Apr 8, 2024
You're right that we lock the entire cache instead of individual keys for value-loading. Back when we implemented this functionality we considered lock-management on a per-key basis a pretty significant overhead.
Cache-locking happens inside RedisCacheWriter. Alternatively, we could reuse RedisCacheWriter's lock and have a lock for the global cache that would also affect other instances of RedisCache on other nodes.
This requires a bit more thought on how refining locking would fit into the bigger picture.
The following code can be found in
org.springframework.data.redis.cache.RedisCache
.I believe there could be a significant amount of unnecessary locking happening here.
I don't think that this method should be locked via an instance-global ReentrantLock instance.
Instead, it should be locked on a per key basis, as follows:
Plus additional cleanup calls to the ConcurrentHashMap for clear and evict calls to RedisCache.
What do you think?
The text was updated successfully, but these errors were encountered: