October 2017
Intermediate to advanced
396 pages
10h 2m
English
You can customize the cache key by using a key attribute of @Cacheable and the @CachePut annotation. The cache key is derived by a SpEL expression using properties of the object as highlighted key attribute in the following snippet of code. Let's look at the following examples:
@Cacheable(cacheNames=" accountCache ", key="#accountId")
public Account findAccount(Long accountId)
@Cacheable(cacheNames=" accountCache ", key="#account.accountId")
public Account findAccount(Account account)
@CachePut(value=" accountCache ", key="#account.accountId")
Account save(Account account);
You can see in the preceding code snippets how we have created the cache key by using the key attribute of the @Cacheable annotation.
Let's ...
Read now
Unlock full access