diff --git a/pom.xml b/pom.xml
index 6b1ed206bd..3c8744d956 100644
--- a/pom.xml
+++ b/pom.xml
@@ -559,7 +559,8 @@
spring-boot-rest
spring-caching
- spring-caching-2
+ spring-caching-2/redis
+ spring-caching-2/ttl
spring-cloud-modules
diff --git a/spring-caching-2/README.md b/spring-caching-2/redis/README.md
similarity index 100%
rename from spring-caching-2/README.md
rename to spring-caching-2/redis/README.md
diff --git a/spring-caching-2/pom.xml b/spring-caching-2/redis/pom.xml
similarity index 97%
rename from spring-caching-2/pom.xml
rename to spring-caching-2/redis/pom.xml
index 60e4873a3c..a772a7b031 100644
--- a/spring-caching-2/pom.xml
+++ b/spring-caching-2/redis/pom.xml
@@ -12,7 +12,7 @@
com.baeldung
parent-boot-2
0.0.1-SNAPSHOT
- ../parent-boot-2
+ ../../parent-boot-2/pom.xml
diff --git a/spring-caching-2/src/main/java/com/baeldung/caching/redis/CacheConfig.java b/spring-caching-2/redis/src/main/java/com/baeldung/caching/redis/CacheConfig.java
similarity index 100%
rename from spring-caching-2/src/main/java/com/baeldung/caching/redis/CacheConfig.java
rename to spring-caching-2/redis/src/main/java/com/baeldung/caching/redis/CacheConfig.java
diff --git a/spring-caching-2/src/main/java/com/baeldung/caching/redis/Item.java b/spring-caching-2/redis/src/main/java/com/baeldung/caching/redis/Item.java
similarity index 100%
rename from spring-caching-2/src/main/java/com/baeldung/caching/redis/Item.java
rename to spring-caching-2/redis/src/main/java/com/baeldung/caching/redis/Item.java
diff --git a/spring-caching-2/src/main/java/com/baeldung/caching/redis/ItemController.java b/spring-caching-2/redis/src/main/java/com/baeldung/caching/redis/ItemController.java
similarity index 100%
rename from spring-caching-2/src/main/java/com/baeldung/caching/redis/ItemController.java
rename to spring-caching-2/redis/src/main/java/com/baeldung/caching/redis/ItemController.java
diff --git a/spring-caching-2/src/main/java/com/baeldung/caching/redis/ItemRepository.java b/spring-caching-2/redis/src/main/java/com/baeldung/caching/redis/ItemRepository.java
similarity index 100%
rename from spring-caching-2/src/main/java/com/baeldung/caching/redis/ItemRepository.java
rename to spring-caching-2/redis/src/main/java/com/baeldung/caching/redis/ItemRepository.java
diff --git a/spring-caching-2/src/main/java/com/baeldung/caching/redis/ItemService.java b/spring-caching-2/redis/src/main/java/com/baeldung/caching/redis/ItemService.java
similarity index 100%
rename from spring-caching-2/src/main/java/com/baeldung/caching/redis/ItemService.java
rename to spring-caching-2/redis/src/main/java/com/baeldung/caching/redis/ItemService.java
diff --git a/spring-caching-2/src/main/java/com/baeldung/caching/redis/RedisCacheApplication.java b/spring-caching-2/redis/src/main/java/com/baeldung/caching/redis/RedisCacheApplication.java
similarity index 100%
rename from spring-caching-2/src/main/java/com/baeldung/caching/redis/RedisCacheApplication.java
rename to spring-caching-2/redis/src/main/java/com/baeldung/caching/redis/RedisCacheApplication.java
diff --git a/spring-caching-2/src/main/resources/application.properties b/spring-caching-2/redis/src/main/resources/application.properties
similarity index 100%
rename from spring-caching-2/src/main/resources/application.properties
rename to spring-caching-2/redis/src/main/resources/application.properties
diff --git a/spring-caching-2/src/main/resources/data.sql b/spring-caching-2/redis/src/main/resources/data.sql
similarity index 100%
rename from spring-caching-2/src/main/resources/data.sql
rename to spring-caching-2/redis/src/main/resources/data.sql
diff --git a/spring-caching-2/src/test/java/com/baeldung/caching/redis/ItemServiceCachingIntegrationTest.java b/spring-caching-2/redis/src/test/java/com/baeldung/caching/redis/ItemServiceCachingIntegrationTest.java
similarity index 100%
rename from spring-caching-2/src/test/java/com/baeldung/caching/redis/ItemServiceCachingIntegrationTest.java
rename to spring-caching-2/redis/src/test/java/com/baeldung/caching/redis/ItemServiceCachingIntegrationTest.java
diff --git a/spring-caching-2/src/test/resources/logback-test.xml b/spring-caching-2/redis/src/test/resources/logback-test.xml
similarity index 100%
rename from spring-caching-2/src/test/resources/logback-test.xml
rename to spring-caching-2/redis/src/test/resources/logback-test.xml
diff --git a/spring-caching-2/ttl/pom.xml b/spring-caching-2/ttl/pom.xml
new file mode 100644
index 0000000000..b7edf90c44
--- /dev/null
+++ b/spring-caching-2/ttl/pom.xml
@@ -0,0 +1,49 @@
+
+
+ 4.0.0
+ spring-caching-3
+ 0.1-SNAPSHOT
+ spring-caching-3
+
+
+ org.springframework.boot
+ spring-boot-starter-parent
+ 2.3.4.RELEASE
+
+
+
+
+ org.springframework.data
+ spring-data-commons
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+ org.springframework.boot
+ spring-boot-starter-data-jpa
+
+
+ org.springframework.boot
+ spring-boot-starter-validation
+
+
+ com.h2database
+ h2
+ runtime
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+ test
+
+
+ com.google.guava
+ guava
+ 30.0-jre
+
+
+
\ No newline at end of file
diff --git a/spring-caching-2/ttl/src/main/java/com/baeldung/caching/ttl/Application.java b/spring-caching-2/ttl/src/main/java/com/baeldung/caching/ttl/Application.java
new file mode 100755
index 0000000000..b8f337bcf7
--- /dev/null
+++ b/spring-caching-2/ttl/src/main/java/com/baeldung/caching/ttl/Application.java
@@ -0,0 +1,13 @@
+package com.baeldung.caching.ttl;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.scheduling.annotation.EnableScheduling;
+
+@SpringBootApplication
+@EnableScheduling
+public class Application {
+ public static void main(String[] args) {
+ SpringApplication.run(Application.class, args);
+ }
+}
\ No newline at end of file
diff --git a/spring-caching-2/ttl/src/main/java/com/baeldung/caching/ttl/config/GuavaCachingConfig.java b/spring-caching-2/ttl/src/main/java/com/baeldung/caching/ttl/config/GuavaCachingConfig.java
new file mode 100644
index 0000000000..bfd0c6ce1e
--- /dev/null
+++ b/spring-caching-2/ttl/src/main/java/com/baeldung/caching/ttl/config/GuavaCachingConfig.java
@@ -0,0 +1,34 @@
+package com.baeldung.caching.ttl.config;
+
+import com.google.common.cache.Cache;
+import com.google.common.cache.CacheBuilder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.concurrent.TimeUnit;
+
+public class GuavaCachingConfig {
+
+ private Cache cache;
+
+ Logger logger = LoggerFactory.getLogger(GuavaCachingConfig.class);
+
+ public GuavaCachingConfig(int expiryDuration, TimeUnit timeUnit) {
+ cache = CacheBuilder.newBuilder()
+ .expireAfterWrite(expiryDuration, timeUnit)
+ .concurrencyLevel(Runtime.getRuntime().availableProcessors())
+ .build();
+ }
+
+ public T get(Long key) {
+ return cache.getIfPresent(key);
+ }
+
+ public void add(Long key, T value) {
+ if(key != null && value != null) {
+ cache.put(key, value);
+ logger.info(
+ String.format("A %s record stored in Cache with key: %s", value.getClass().getSimpleName(), key));
+ }
+ }
+}
\ No newline at end of file
diff --git a/spring-caching-2/ttl/src/main/java/com/baeldung/caching/ttl/config/SpringCachingConfig.java b/spring-caching-2/ttl/src/main/java/com/baeldung/caching/ttl/config/SpringCachingConfig.java
new file mode 100644
index 0000000000..555933c0c1
--- /dev/null
+++ b/spring-caching-2/ttl/src/main/java/com/baeldung/caching/ttl/config/SpringCachingConfig.java
@@ -0,0 +1,17 @@
+package com.baeldung.caching.ttl.config;
+
+import org.springframework.cache.CacheManager;
+import org.springframework.cache.annotation.EnableCaching;
+import org.springframework.cache.concurrent.ConcurrentMapCacheManager;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+@EnableCaching
+public class SpringCachingConfig {
+
+ @Bean
+ public CacheManager cacheManager() {
+ return new ConcurrentMapCacheManager("hotels");
+ }
+}
\ No newline at end of file
diff --git a/spring-caching-2/ttl/src/main/java/com/baeldung/caching/ttl/controller/HotelController.java b/spring-caching-2/ttl/src/main/java/com/baeldung/caching/ttl/controller/HotelController.java
new file mode 100755
index 0000000000..f1a90eb950
--- /dev/null
+++ b/spring-caching-2/ttl/src/main/java/com/baeldung/caching/ttl/controller/HotelController.java
@@ -0,0 +1,36 @@
+package com.baeldung.caching.ttl.controller;
+
+import com.baeldung.caching.ttl.service.HotelService;
+import com.baeldung.caching.ttl.model.Hotel;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.ResponseStatus;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.List;
+
+@RestController
+@RequestMapping("/hotel")
+public class HotelController {
+ private final HotelService hotelService;
+
+ @Autowired
+ public HotelController(HotelService hotelService) {
+ this.hotelService = hotelService;
+ }
+
+ @GetMapping
+ @ResponseStatus(HttpStatus.OK)
+ public List getAllHotels() {
+ return hotelService.getAllHotels();
+ }
+
+ @GetMapping(value = "/{id}")
+ @ResponseStatus(HttpStatus.OK)
+ public Hotel getHotelById(@PathVariable Long id) {
+ return hotelService.getHotelById(id);
+ }
+}
\ No newline at end of file
diff --git a/spring-caching-2/ttl/src/main/java/com/baeldung/caching/ttl/exception/ControllerAdvisor.java b/spring-caching-2/ttl/src/main/java/com/baeldung/caching/ttl/exception/ControllerAdvisor.java
new file mode 100644
index 0000000000..519f147929
--- /dev/null
+++ b/spring-caching-2/ttl/src/main/java/com/baeldung/caching/ttl/exception/ControllerAdvisor.java
@@ -0,0 +1,26 @@
+package com.baeldung.caching.ttl.exception;
+
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.ControllerAdvice;
+import org.springframework.web.bind.annotation.ExceptionHandler;
+import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+@ControllerAdvice
+public class ControllerAdvisor extends ResponseEntityExceptionHandler {
+
+ @ExceptionHandler(ElementNotFoundException.class)
+ public ResponseEntity