August 2017
Intermediate to advanced
332 pages
9h 16m
English
When the cache is configured, we can finally add caching to our web service. In order to do this, we need to change the src/main/java/com/leszko/calculator/Calculator.java file to look as follows:
package com.leszko.calculator;import org.springframework.cache.annotation.Cacheable;import org.springframework.stereotype.Service;/** Calculator logic */@Servicepublic class Calculator { @Cacheable("sum") public int sum(int a, int b) { return a + b; }}
From now on, the sum calculations are cached in Redis, and when we call the /sum endpoint of the calculator web service, it will first try to retrieve the result from the cache.
Read now
Unlock full access