qaware / collection-cacheable-for-spring

Spring cache extension for putting a whole collection of entities as single cache items
Apache License 2.0
58 stars 9 forks source link

Bug when id params have same id, returnValue will occur same result if cache expired in loop #44

Open Laverrr opened 1 year ago

Laverrr commented 1 year ago

we get idsArgument from CollectionCacheableCacheInterceptor#injectCollectionArgument. but when args have the same id params, we will get repeated id in idsArgument.

Then when the method run into CollectionCacheableCacheInterceptor#findIdsInCache

because idsArgument is run in loop,if have two or more same id occur. The first id hit cache will put into cacheResult.

At that time, if cache expired. The next the id will not match cache and then get result from DB, then put the result into uncachedResult.

when merge uncachedResult and cacheResult. The returnValue will occur two or more same id result when use ListReturnValueConverter

Laverrr commented 1 year ago

The way to fix the bug is return distinct idsArgument in method CollectionCacheableCacheInterceptor#injectCollectionArgument