Closed
Description
I hava some ids to find users :
List<User> users = ids.stream().map(id -> {
return getUserById(id);
})
.collect(Collectors.toList());
@Cacheable(key = "#p0", unless = "#result == null")
public User getUserById(Long id) {
...
}
I can also use :
List<User> users = ids.stream().map(id -> {
return getUserById(id);
})
.collect(Collectors.toList());
@Cacheable(key = "#ids.hash")
public Collection<User> getUsersByIds(Collection<Long> ids) {
...
}
but getUsersByIds(Collection ids) cache and getUserById(Long id) cache cannot be shared
why does spring cache not support ids cache?
I want them to share the cache
Metadata
Metadata
Assignees
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
shenjianeng commentedon Dec 5, 2019
RedisCache
key: ids.hash
value: list
invoke method:
I need clear RedisCache(key:ids.hash)
it is not graceful
snicoll commentedon Dec 7, 2019
Thanks for the report. The cache abstraction has no notion of such state, if you return a
Collection
, that's effectively what you're asking to store in the cache. Nothing forces you to keep the same item type for a given cache either so that kind of assumptions is not a great candidate for such a high-level abstraction.The discussion in #23221 is also relevant.
ms100 commentedon Feb 3, 2023
You can use Cache As Multi
shenjianeng commentedon Feb 3, 2023