Here is what I ended up with, trick was to use 'unless' to our advantage
@Cacheable(value="books", key="#isbn", unless = "#result == null") public Book findBookFromCache(ISBN isbn, boolean checkWarehouse, boolean includeUsed) { return null; }
this method
- Looks up in the cache based on key
- if found return the result from cache
- if not found evaluates method that return null
- return value is matched with unless condition (which always return true)
- null value do not get cached
- null value is returned to caller
Read full article from spring - How to make @Cacheable return null when not found in cache but do not cache the result? - Stack Overflow
No comments:
Post a Comment