0
0
Spring Bootframework~10 mins

Redis as cache provider 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
Cexecute
Dlaunch
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 support in Spring Boot.

Spring Boot
@Configuration
[1]
public class CacheConfig {
}
Drag options to blanks, or click blank then click option'
A@EnableScheduling
B@EnableTransactionManagement
C@EnableAsync
D@EnableCaching
Attempts:
3 left
💡 Hint
Common Mistakes
Using @EnableScheduling or other unrelated annotations.
Forgetting to add any caching annotation.
3fill in blank
hard

Fix the error in the Redis cache manager bean definition.

Spring Boot
@Bean
public RedisCacheManager cacheManager(RedisConnectionFactory factory) {
    return RedisCacheManager.[1](factory).build();
}
Drag options to blanks, or click blank then click option'
Abuilder
BBuilder
Ccreate
DbuilderFactory
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'create' or 'Builder' causes compilation errors.
Using incorrect method names for builder pattern.
4fill in blank
hard

Fill both blanks to configure a RedisTemplate bean with String keys and values.

Spring Boot
@Bean
public RedisTemplate<String, String> redisTemplate(RedisConnectionFactory factory) {
    RedisTemplate<String, String> template = new RedisTemplate<>();
    template.setConnectionFactory([1]);
    template.setKeySerializer([2]);
    return template;
}
Drag options to blanks, or click blank then click option'
Afactory
Bnew StringRedisSerializer()
Cnew GenericJackson2JsonRedisSerializer()
DconnectionFactory
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong serializer for keys causes data issues.
Passing wrong variable name for connection factory.
5fill in blank
hard

Fill both blanks to create a cacheable service method with Redis cache.

Spring Boot
public class UserService {

    @Cacheable(cacheNames = [1])
    public User getUserById([2] id) {
        // fetch user from database
        return userRepository.findById(id);
    }
}
Drag options to blanks, or click blank then click option'
A"users"
BLong
Cint
D"userCache"
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong cache name string or missing quotes.
Using wrong parameter type like int instead of Long.