Search code examples
javaspringspring-integrationspring-el

Spring cacheable - filter out empty collections using SpEL


I wanted to know is there a way to use SpEL in order to filter out values like empty collections.

My cache currently filters out null values:

  @Cacheable(value = "groupIdToGroupNames",unless = "#result == null")
   public Map<Long, Collection<String>> findAllBySearchCustomerKey(final long groupId) {
    return idToNameClient.findAllGroupMembersById(groupId);
   } 

I'm trying to find a way to filter out the groups that are of size 0 but not null. Is there a way of doing that by using params for @Cacheable?

Any help would be much appreciated.


Solution

  • Something like this

    unless = "#result==null or #result.size()==0"
    

    More about result and or.