An article showing how to configure Ehcache in Spring Boot application. It’s covered for both Ehcache 2 and Ehcache 3.

In another article, I have introduced to Spring Cache Abstraction. Following that article, In this article, I am going to show you how to configure Ehcache in the Spring Boot application(similarly, you can do for non-spring application by adding more dependencies).

configure ehcache in spring boot
configure ehcache in spring boot

Before jumping to the code demo section, I want to have a quick introduction to , module, and module. Going through these pieces should be great to understand more what I do in the code demo section.

What is Ehcache?


Caching is well-known as the most approach to increase application performance. Caching helps reduce the cost of CPU expensive operations such as Fibonacci calculation. Besides CPU expensive operations, caching also helps reduce IO expensive operations such as reading files from disk. Unfortunately, efficiently applying cache into the application is no simple task.

Providing an abstraction caching layer.

Spring Framework provides cache implementation in the spring-context module with a simple cache store that is ConcurrentHashMapif no cache library found on the classpath. Otherwise, in case we have included supported cache libraries in the classpath,

With the spring cache, It has many built-in annotations to manage cache by common actions such as write to cache, evict cache, or update cache. We will jump into detail of Spring Cache annotations in the next section. …


This article shows you how to do paging and sorting data with Spring Data JPA.

Image for post
Image for post
Photo by Edu Grande on Unsplash

Any good developers know that fetching large data then render the view or response within a single request is a bad idea for a high-performance application. So in this article, I would like to share with you how to do paging and sort data with Spring Data JPA. This article gives you a solution to handle the most popular feature in most applications such as displaying products in the e-commerce system.

How Spring JPA supports paging and sorting data

Before going to the demo, I would like to share with you how Spring Data JPA supports developers for doing paging and sorting.


Spring Data JPA already provides many solutions that allow us querying data easier such as Query Method, Query Method, or four repository interface(JpaRepository, PagingAndSortingRepository, CrudRepository, Repository). These features are powerful, which help me a lot when building an application with Spring Data JPA. But a lot of time we still need to custom query or method to meet expectations or requirements.

Custom Repository in Spring Data JPA
Custom Repository in Spring Data JPA

The class design diagram above indicates how we can create a custom repository in Spring Data JPA. We just need to let EmployeeRepository implement the custom interface and define the implementation for the customized repository. …


Version Control is very important to make sure any change in the source code should be recorded and allow us to recall a specific version later. Imagine we edit some lines of code then deploy it without full-test then the error occurs due to the changes, unfortunately, we forgot to make a backup of the old code. Now how do we can revert to the previous version? In order to avoid these problems, we need a version control system to record and keep track of all changes in our code.

A version control system allows us to revert a selected file back to a previous version or revert the entire project. It also allows us to see who last modified and so on. …


This article shows you how to configure the H2 database within a Spring Boot application.

What is H2 database?

H2 database is an open-source in-memory database that can be easily embedded into Java application. H2 database provides a list of features such as Pure Java, memory mode, encrypted database, ODBC driver even full-text search. Its size approx around 2MB.

H2 database also provides a browser-based Console application to manage data.

h2 database browser-based Console application
h2 database browser-based Console application
h2 browser-based console application


In this article, we will learn about message term in Spring Integration

Image for post
Image for post
Photo by Anne Nygård on Unsplash

In order to loose coupling between components in a system, we typically apply the messaging system to achieve that aim. That requires a solid understanding of what is a message and some type of message for effective use for specific scenarios. So in this article, I would like to share the definition of the message, the structure of a message, and common types of messages in a messaging system.

What is a message in a messaging system?

As the spring integration reference document defined that “


In modern software architecture, the application needs to be decoupled, high scalability, serving high performance. Messaging service come in allows us to build that kind of application. Therefore with a solid understanding of messaging models is the key to build an effective system. There are two commonly messaging models, the and the model. Both of these messaging models are based on the message queue know as a central place to send messages to or place to get the message from. The sent messages are ordered in the message queue except it has higher priority. …


In Java language, it has two types of variables, primitive variable, and reference variable. In some cases, we want to use the primitive variable as an object to get the benefits of an object like allowing null or encapsulation. For those cases, we can use wrapper classes to do that thing. There are eight classes to wrap the primitive value in an object in Java language:

  • java.lang.Byte wraps byte value
  • java.lang.Short wraps short value
  • java.lang.Integer wraps int value
  • java.lang.Long wraps long value
  • java.lang.Float wraps float value
  • java.lang.Double wraps double value
  • java.lang.Char wraps char value
  • java.lang.Boolean wraps boolean value
wrapper class in java
wrapper class in java
Wrapper class inheritance tree

A wrapper class is like a box where we can put the primitive value. The box has holes that allow us to put values from different types or convert the holding value to another type. …


The article shows what is in-memory caching, how does it work, and some terms we need to know when to do cache for the application.

As we know, any server or computer stores data on the hard disk and in the RAM(Random Access Memory). The RAM is the temporary storage while the hard disk is the permanent computer storage. When comparing the speed of these storages, RAM has extremely faster than hard disk even of SSD. RAM can transfer thousands of megabytes per second while the hard disk only gives us around 50 to 250MB/s. Now we might think that we can temporarily store data in RAM to increase reading and writing speed for the application. The act of temporarily storing data in a RAM is called in-memory caching. …

About

Thanh Tran

Software Engineer, I am passionate about software development and love to share my knowledge with all of you.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store