Caching with Spring
Caching with Spring: @Cacheable, @CacheEvict, @CachePut, CacheManager, providers (EhCache, Redis, Caffeine)
1What is the main role of the @Cacheable annotation in Spring?
What is the main role of the @Cacheable annotation in Spring?
Respuesta
@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.
2Which annotation is required to enable caching support in a Spring Boot application?
Which annotation is required to enable caching support in a Spring Boot application?
Respuesta
@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.
3What is the main difference between @Cacheable and @CachePut?
What is the main difference between @Cacheable and @CachePut?
Respuesta
@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.
What is the role of the @CacheEvict annotation in Spring?
Which CacheManager does Spring Boot configure by default if no other is defined?
+22 preguntas de entrevista
Otros temas de entrevista Spring Boot
Spring Core - IoC & DI
Spring Boot Auto-Configuration
Spring Boot Starters
Application Properties & YAML
Logging with SLF4J & Logback
Spring Boot DevTools
Spring MVC Basics
Spring REST Controllers
Request & Response Handling
Exception Handling
Bean Validation
Spring Data JPA Basics
JPA Entities & Relationships
JPA Queries
Spring Data Repositories
Spring Security Basics
Spring Boot Actuator
Unit Testing with JUnit & Mockito
Spring Boot Testing
Profiles & Environment
RestTemplate & WebClient
Async & Scheduling
Spring WebFlux (Reactive)
Spring Transactions
Advanced Authentication & Authorization
JWT & Stateless Security
OAuth2 & Authorization Server
Spring Boot & Docker
Microservices with Spring
Spring Cloud Config
Performance Optimization
GraalVM Native Images
Domina Spring Boot para tu próxima entrevista
Accede a todas las preguntas, flashcards, tests técnicos, ejercicios de code review y simuladores de entrevista.
Empieza gratis