Description
David Tanner opened DATAREDIS-678 and commented
https://docs.spring.io/spring/docs/current/spring-framework-reference/html/cache.html
Synchronized caching
*
In a multi-threaded environment, certain operations might be concurrently invoked for the same argument (typically on startup). By default, the cache abstraction does not lock anything and the same value may be computed several times, defeating the purpose of caching.
For those particular cases, the sync attribute can be used to instruct the underlying cache provider to lock the cache entry while the value is being computed. As a result, only one thread will be busy computing the value while the others are blocked until the entry is updated in the cache.*
However, the cache is not locked based on the key/entry, it is only locked using the cache name.
https://github.com/spring-projects/spring-data-redis/blob/1.8.x/src/main/java/org/springframework/data/redis/cache/RedisCache.java#L381
This also goes against the documentation in Cacheable.java
"Synchronize the invocation of the underlying method if several threads are attempting to load a value for the same key. The synchronization leads to a couple of limitations:"
Based on the documentation, the lock should also be based on the cache key. Currently the functionality takes away the most compelling reason to use the sync attribute on a slow, high throughput method with a wide variety of parameters
Affects: 1.8.6 (Ingalls SR6)
Issue Links:
- DATAREDIS-1100 Spring Cacheable sync=true not working across multiple instances
3 votes, 5 watchers