jeff porter opened SPR-16410 and commented
If we annotate a method with the following...
@Cacheable(value = "hardware.devices", key = "#hardwareId", unless="#result == null", sync=true)
Then we get an exception (@Cacheable(sync=true) does not support unless attribute on )
This means that there is no way to config the cache to NOT cache null objects if sync is used.
If the option of "sync" is not provided, then we can use the parameter unless.
I feel this should be considered a defect.
Affects: 4.3.14, 5.0.3
2 votes, 3 watchers
Comment From: spring-projects-issues
Stéphane Nicoll commented
It isn't a defect but a limitation of the sync operation and the Javadoc of sync clearly states that it isn't supported.
Comment From: fstonezst
Will sync support unless in the future? @spring-issuemaster
Comment From: IQException
why not support
Comment From: snicoll
the synchronization option means that the cache library is in full control of the "get if found and load and cache otherwise". There is no room for us to add an additional check as the underlying API does not offer a way to hook into the process. And said API is different for each cache provider.
The very purpose of sync is to let the cache library do the work, acquiring locks in the most optimized manner. Us supporting this option means we'll have to get rid of that and implement the lock ourselves which I don't think is a good idea.
If you need to use unless then you should reconsider whether or not that sync optimization is required.