Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 279
user2512231 Avatar asked Sep 22 '14 15:09

user2512231


2 Answers

Something like this

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

More about result and or.

like image 138
Artem Bilan Avatar answered Nov 12 '22 11:11

Artem Bilan


unless = "#result==null or #result.isEmpty()" works for me.

like image 41
NanoNova Avatar answered Nov 12 '22 12:11

NanoNova