June 2017
Intermediate to advanced
496 pages
14h 4m
English
Now that we have enabled caching, we can add the ;@Cacheable annotation to the methods where we want to cache the data. The following code snippet shows how to enable caching on retrieveTodos:
@Cacheable("todos") public List<Todo> retrieveTodos(String user) {
In the preceding example, the todos for a specific user are cached. On the first call to the method for a specific user, the todos will be retrieved from the service. On subsequent calls for the same user, the data will be returned from the cache.
Spring also provides conditional caching. In the following snippet, caching is enabled only if the specified condition is satisfied:
@Cacheable(cacheNames="todos", condition="#user.length < 10”) public List<Todo> retrieveTodos(String ...
Read now
Unlock full access