0
0
Spring Bootframework~10 mins

Cache configuration in Spring Boot - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to enable caching in a Spring Boot application.

Spring Boot
@SpringBootApplication
public class Application {
    public static void main(String[] args) {
        SpringApplication.[1](Application.class, args);
    }
}
Drag options to blanks, or click blank then click option'
Arun
Bstart
Claunch
Dexecute
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'start' or 'launch' instead of 'run' causes errors.
Forgetting to call any method to start the app.
2fill in blank
medium

Complete the annotation to enable caching in a Spring Boot application.

Spring Boot
@Configuration
@[1]
public class CacheConfig {
}
Drag options to blanks, or click blank then click option'
AEnableCaching
BCacheable
CCacheConfig
DEnableCache
Attempts:
3 left
💡 Hint
Common Mistakes
Using @Cacheable on configuration class instead of @EnableCaching.
Misspelling the annotation name.
3fill in blank
hard

Fix the error in the cacheable method annotation to cache the result.

Spring Boot
@Service
public class ProductService {

    @Cacheable(cacheNames = "products", key = "#[1]")
    public Product getProductById(Long id) {
        // fetch product
    }
}
Drag options to blanks, or click blank then click option'
Akey
BproductId
Cid
Dvalue
Attempts:
3 left
💡 Hint
Common Mistakes
Using a key that does not match any parameter causes runtime errors.
Omitting the '#' in the SpEL expression.
4fill in blank
hard

Fill both blanks to configure a cache manager bean using ConcurrentMapCacheManager.

Spring Boot
@Configuration
public class CacheConfig {

    @Bean
    public CacheManager cacheManager() {
        return new [1](List.of("[2]"));
    }
}
Drag options to blanks, or click blank then click option'
AConcurrentMapCacheManager
BRedisCacheManager
Cproducts
Dusers
Attempts:
3 left
💡 Hint
Common Mistakes
Using RedisCacheManager without Redis dependencies.
Mismatching cache names causes cache misses.
5fill in blank
hard

Fill all three blanks to create a cacheable method that caches by user ID and cache name 'users'.

Spring Boot
@Service
public class UserService {

    @Cacheable(cacheNames = "[1]", key = "#[2]")
    public User getUserById(Long [3]) {
        // fetch user
    }
}
Drag options to blanks, or click blank then click option'
Ausers
Bid
CuserId
Dproducts
Attempts:
3 left
💡 Hint
Common Mistakes
Using different names for key and parameter causes cache failures.
Using wrong cache names leads to no caching.