0
0
Spring Bootframework~20 mins

@EnableCaching annotation in Spring Boot - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Caching Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What happens when @EnableCaching is added to a Spring Boot application?
Consider a Spring Boot application with a service method annotated with @Cacheable. What is the effect of adding @EnableCaching to the main configuration class?
Spring Boot
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableCaching
public class AppConfig {
}
AIt automatically creates a cache store but does not enable caching on any methods.
BIt disables all caching in the application, forcing methods to always execute fully.
CIt activates Spring's annotation-driven cache management, enabling caching behavior on methods annotated with @Cacheable.
DIt only enables caching for methods annotated with @CachePut, ignoring @Cacheable annotations.
Attempts:
2 left
💡 Hint
Think about what @EnableCaching does in relation to @Cacheable methods.
📝 Syntax
intermediate
1:30remaining
Identify the correct way to enable caching in a Spring Boot application
Which of the following code snippets correctly enables caching in a Spring Boot application?
A
@Configuration
@EnableCaching
public class CacheConfig {}
B
@EnableCaching
public class CacheConfig {}
C
@Configuration
@EnableCache
public class CacheConfig {}
D
@Configuration
@EnableCaching(true)
public class CacheConfig {}
Attempts:
2 left
💡 Hint
Remember the exact annotation name and required annotations for configuration classes.
🔧 Debug
advanced
2:30remaining
Why does caching not work despite @EnableCaching being present?
Given the following code, why might caching not be working as expected? @Configuration @EnableCaching public class AppConfig {} @Service public class MyService { @Cacheable("items") public String getItem(String id) { return "Item" + id; } } Assume the application runs but caching does not reduce method calls.
AThe @EnableCaching annotation must be placed on the service class, not the configuration class.
BThe cache name "items" is invalid and must be registered explicitly in the cache manager.
CThe @Cacheable annotation requires a key attribute to work properly.
DThe service method is called from within the same class, so Spring's proxy does not intercept the call to apply caching.
Attempts:
2 left
💡 Hint
Think about how Spring proxies work and when caching applies.
🧠 Conceptual
advanced
2:00remaining
What is the role of @EnableCaching in Spring's caching abstraction?
Which statement best describes the role of @EnableCaching in a Spring application?
A@EnableCaching disables caching unless a custom cache manager bean is provided.
B@EnableCaching activates the processing of caching annotations and configures a cache manager if none is defined.
C@EnableCaching replaces the need to annotate methods with @Cacheable or other caching annotations.
D@EnableCaching automatically creates and manages all caches without any further configuration.
Attempts:
2 left
💡 Hint
Consider what enabling caching means for annotation processing and cache manager setup.
state_output
expert
2:30remaining
What is the output count of method calls with @EnableCaching and @Cacheable?
Given this Spring Boot service: @Service public class CounterService { private int count = 0; @Cacheable("numbers") public int getNumber(int input) { count++; return input * 2; } public int getCount() { return count; } } And this test code: CounterService service = context.getBean(CounterService.class); service.getNumber(5); service.getNumber(5); service.getNumber(10); service.getNumber(5); int calls = service.getCount(); What is the value of calls after these calls if @EnableCaching is present?
A2
B1
C4
D3
Attempts:
2 left
💡 Hint
Remember that @Cacheable caches results by method parameters.