Complete the code to enable caching on a Spring Boot method.
@Cacheable([1])
public String getData() {
// method logic
}The @Cacheable annotation requires the name of the cache as a string parameter. Here, "dataCache" is the cache name.
Complete the code to add caching support in a Spring Boot application.
@SpringBootApplication @Enable[1] public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } }
The @EnableCaching annotation activates Spring's annotation-driven cache management capability.
Fix the error in the caching annotation usage.
@Cacheable(cacheNames = [1])
public String fetchData() {
// fetch data logic
}The cacheNames attribute expects a string or array of strings. The cache name must be quoted.
Fill both blanks to create a cache configuration bean.
@Bean public CacheManager [1]() { return new [2](); }
The method name is typically cacheManager, and ConcurrentMapCacheManager is a simple cache manager implementation.
Fill all three blanks to create a cacheable method with a key.
@Cacheable(value = [1], key = "#[2]") public String getUserData([3] userId) { // method logic }
The cache name is "userCache". The key uses the method parameter name userId. The parameter type is String.