Spring Boot With Ehcache
This commit is contained in:
0
Spring-Boot/spring-boot-ehcache/.gitignore
vendored
Normal file → Executable file
0
Spring-Boot/spring-boot-ehcache/.gitignore
vendored
Normal file → Executable file
0
Spring-Boot/spring-boot-ehcache/.mvn/wrapper/MavenWrapperDownloader.java
vendored
Normal file → Executable file
0
Spring-Boot/spring-boot-ehcache/.mvn/wrapper/MavenWrapperDownloader.java
vendored
Normal file → Executable file
0
Spring-Boot/spring-boot-ehcache/.mvn/wrapper/maven-wrapper.jar
vendored
Normal file → Executable file
0
Spring-Boot/spring-boot-ehcache/.mvn/wrapper/maven-wrapper.jar
vendored
Normal file → Executable file
0
Spring-Boot/spring-boot-ehcache/.mvn/wrapper/maven-wrapper.properties
vendored
Normal file → Executable file
0
Spring-Boot/spring-boot-ehcache/.mvn/wrapper/maven-wrapper.properties
vendored
Normal file → Executable file
0
Spring-Boot/spring-boot-ehcache/mvnw.cmd
vendored
Normal file → Executable file
0
Spring-Boot/spring-boot-ehcache/mvnw.cmd
vendored
Normal file → Executable file
0
Spring-Boot/spring-boot-ehcache/pom.xml
Normal file → Executable file
0
Spring-Boot/spring-boot-ehcache/pom.xml
Normal file → Executable file
0
Spring-Boot/spring-boot-ehcache/src/main/java/com/javadevjournal/SpringBootWithEhcacheApplication.java
Normal file → Executable file
0
Spring-Boot/spring-boot-ehcache/src/main/java/com/javadevjournal/SpringBootWithEhcacheApplication.java
Normal file → Executable file
0
Spring-Boot/spring-boot-ehcache/src/main/java/com/javadevjournal/config/AppConfig.java
Normal file → Executable file
0
Spring-Boot/spring-boot-ehcache/src/main/java/com/javadevjournal/config/AppConfig.java
Normal file → Executable file
0
Spring-Boot/spring-boot-ehcache/src/main/java/com/javadevjournal/config/CustomCacheEventLogger.java
Normal file → Executable file
0
Spring-Boot/spring-boot-ehcache/src/main/java/com/javadevjournal/config/CustomCacheEventLogger.java
Normal file → Executable file
7
Spring-Boot/spring-boot-ehcache/src/main/java/com/javadevjournal/controller/CustomerController.java
Normal file → Executable file
7
Spring-Boot/spring-boot-ehcache/src/main/java/com/javadevjournal/controller/CustomerController.java
Normal file → Executable file
@@ -8,6 +8,8 @@ import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/customers")
|
||||
public class CustomerController {
|
||||
@@ -19,4 +21,9 @@ public class CustomerController {
|
||||
public Customer getCustomer(@PathVariable Long id){
|
||||
return customerService.getCustomer(id);
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public List<Customer> getCustomers(){
|
||||
return customerService.getCustomers();
|
||||
}
|
||||
}
|
||||
|
||||
0
Spring-Boot/spring-boot-ehcache/src/main/java/com/javadevjournal/data/Customer.java
Normal file → Executable file
0
Spring-Boot/spring-boot-ehcache/src/main/java/com/javadevjournal/data/Customer.java
Normal file → Executable file
18
Spring-Boot/spring-boot-ehcache/src/main/java/com/javadevjournal/service/CustomerService.java
Normal file → Executable file
18
Spring-Boot/spring-boot-ehcache/src/main/java/com/javadevjournal/service/CustomerService.java
Normal file → Executable file
@@ -6,6 +6,9 @@ import org.slf4j.LoggerFactory;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class CustomerService {
|
||||
|
||||
@@ -22,4 +25,19 @@ public class CustomerService {
|
||||
customer.setEmail("contact-us@javadevjournlal.com");
|
||||
return customer;
|
||||
}
|
||||
|
||||
@Cacheable(cacheNames = "customerList",key = "'customerList'")
|
||||
public List<Customer> getCustomers(){
|
||||
List<Customer> customers = new ArrayList<>();
|
||||
LOG.info("Returning customer list");
|
||||
for(int i=0; i< 4; i++){
|
||||
Customer customer = new Customer();
|
||||
customer.setCustomerId(Long.valueOf(i));
|
||||
customer.setFirstName("FirstName"+i);
|
||||
customer.setLastName("LastName"+i);
|
||||
customer.setEmail("contact-us@javadevjournlal.com"+i);
|
||||
customers.add(customer);
|
||||
}
|
||||
return customers;
|
||||
}
|
||||
}
|
||||
|
||||
0
Spring-Boot/spring-boot-ehcache/src/main/resources/application.properties
Normal file → Executable file
0
Spring-Boot/spring-boot-ehcache/src/main/resources/application.properties
Normal file → Executable file
27
Spring-Boot/spring-boot-ehcache/src/main/resources/ehcache.xml
Normal file → Executable file
27
Spring-Boot/spring-boot-ehcache/src/main/resources/ehcache.xml
Normal file → Executable file
@@ -8,8 +8,31 @@
|
||||
</service>
|
||||
|
||||
<cache alias="customer">
|
||||
<key-type>java.lang.Long</key-type>
|
||||
<value-type>com.javadevjournal.data.Customer</value-type>
|
||||
<key-type>java.lang.Long</key-type>
|
||||
<value-type>com.javadevjournal.data.Customer</value-type>
|
||||
<expiry>
|
||||
<ttl unit="seconds">10</ttl>
|
||||
</expiry>
|
||||
<listeners>
|
||||
<listener>
|
||||
<class>com.javadevjournal.config.CustomCacheEventLogger</class>
|
||||
<event-firing-mode>ASYNCHRONOUS</event-firing-mode>
|
||||
<event-ordering-mode>UNORDERED</event-ordering-mode>
|
||||
<events-to-fire-on>CREATED</events-to-fire-on>
|
||||
<events-to-fire-on>UPDATED</events-to-fire-on>
|
||||
<events-to-fire-on>EXPIRED</events-to-fire-on>
|
||||
<events-to-fire-on>REMOVED</events-to-fire-on>
|
||||
<events-to-fire-on>EVICTED</events-to-fire-on>
|
||||
</listener>
|
||||
</listeners>
|
||||
<resources>
|
||||
<heap unit="entries">2000</heap>
|
||||
<offheap unit="MB">100</offheap>
|
||||
</resources>
|
||||
</cache>
|
||||
<cache alias="customerList">
|
||||
<key-type>java.lang.String</key-type>
|
||||
<value-type>java.util.ArrayList</value-type>
|
||||
<expiry>
|
||||
<ttl unit="seconds">10</ttl>
|
||||
</expiry>
|
||||
|
||||
0
Spring-Boot/spring-boot-ehcache/src/test/java/com/javadevjournal/SpringBootWithEhcacheApplicationTests.java
Normal file → Executable file
0
Spring-Boot/spring-boot-ehcache/src/test/java/com/javadevjournal/SpringBootWithEhcacheApplicationTests.java
Normal file → Executable file
Reference in New Issue
Block a user