Spring Boot

Caching with Spring

Caching with Spring: @Cacheable, @CacheEvict, @CachePut, CacheManager, providers (EhCache, Redis, Caffeine)

25 면접 질문·
Mid-Level
1

What is the main role of the @Cacheable annotation in Spring?

답변

@Cacheable caches a method's result to avoid repeated executions with the same parameters. This significantly improves performance for expensive operations like database queries or external API calls. Use @Cacheable for frequently called read methods with the same arguments to reduce load on resources.

2

Which annotation is required to enable caching support in a Spring Boot application?

답변

@EnableCaching activates caching support in Spring Boot and must be placed on a configuration class (typically the main class annotated with @SpringBootApplication). Without this annotation, cache annotations like @Cacheable will be ignored. Spring Boot automatically configures a simple in-memory CacheManager (ConcurrentMapCacheManager) if no other is defined.

3

What is the main difference between @Cacheable and @CachePut?

답변

@Cacheable skips method execution if the result is already cached, while @CachePut always executes the method and updates the cache with the new result. Use @Cacheable for reads (avoid repeated calculations) and @CachePut for update operations that must refresh the cache without bypassing method execution.

4

What is the role of the @CacheEvict annotation in Spring?

5

Which CacheManager does Spring Boot configure by default if no other is defined?

+22 면접 질문

다음 면접을 위해 Spring Boot을 마스터하세요

모든 질문, flashcards, 기술 테스트, 코드 리뷰 연습, 면접 시뮬레이터에 접근하세요.

무료로 시작하기