Announcement Announcement Module
Collapse
No announcement yet.
[Help] how can I conditionaly cache result according to the method return result? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • [Help] how can I conditionaly cache result according to the method return result?

    I want cache my method return result only if the return doesn't NULL,
    I browsed the I found Spring cache manual
    the description like below;

    result evaluation context The result of the method call (the value to be cached). Only available in 'unless' expressions and 'cache evict' expression (when beforeInvocation is false).
    #result
    it say only unless expression can use #result expression?

    who can give me an example, I can't understand this.
    the below code doesn't runs as I expected.
    I mean the result shouldn't be cached when return NULL.
    Code:
    @Cacheable(value = "users", condition = "#result ne null")
        public User findByName(String username) throws DataAccessException
Working...
X