How to avoid caching null values in redis cache

2.3k Views Asked by At
@CacheResult(cacheName = "testCache)
public Employee geteEmployee(@CacheKey String empId) {
   //logic
   return employee;
}

If employee is null, that null value should not be cached.

1

There are 1 best solutions below

5
peterulb On

You can set the cacheNull property to false.

cacheNull

public abstract boolean cacheNull

If set to false null return values will not be cached. If true (the default) null return values will be cached.

Defaults to true.

Default: true

@CacheResult(cacheName = "testCache", cacheNull = false)