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).
Before jumping to the code demo section, I want to have a quick introduction to Ehcache, spring-boot-autoconfigure module, and spring-context-support module. Going through these pieces should be great to understand more what I do in the code demo section.
Ehcache is an open-source, standards-based cache that boosts performance, offloads your database, and simplifies scalability. It’s the most widely-used Java-based…
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.
Spring Framework provides cache implementation in the spring-context module with a simple cache store that is ConcurrentHashMap
if 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…
As a java developer, I guest that you heard about the connection pool and might apply it to your system. Therefore in this article, we will learn how to configure C3P0 which is the most popular connection-pool library for java developers.
If you are a fan of Start War you might think C3P0 is this guy.
At my first time hearing about the connection pool and saw C3P0, I have made a mistake about the ZERO and O letter. I did not know and googling c3po and google show me this guy and I was confused. …
Custom domain service was turned back in Medium that helps us to add our domain to point to. I really like this feature because it improves the branding for our publication. So in this article, I will guide you to add a custom domain point to your publication.
Medium requires membership for adding custom domain therefore you have to upgrade your account before continuing to the next process.
Check out this page to learn more about Medium membership and subscribe to become a member.
In case you already have your own domain, skip this step.
To buy a domain, we…
Have you ever face a problem that you changing the entity field and then the application throw exception at runtime due to the change? If you have been facing that problem I think using type-safe queries might be a good choice.
When writing query statements we mostly use JPQL or native query and write literally in string.
I purposely wrote the wrong query but we got no warning from the compiler because it has no way to detect such errors. …
Let start with an example of saving order information. In many cases to store order information, we will have two tables let call Order and OrderLine. In consequently the system must save data for the order first then sort info of order line items. Now have to think about the case we save Order data successfully but the OrderLine failed. For this case, we have to rollback the order info to be not saved in the database to guarantee the consistency of the order information. In such problems, we have to use transactions.
In java or other languages, the developer…
Follow part one of the CRUD document using MongoTemplate series which shares about inserting documents, in this article, we will learn how to update documents by using MongoTemplate.
MongoTemplate provides a save method that allows updating documents. The diagram below shows how the save
method work in basic.
Spring Data MongoDB provides a class named MongoTemplate
which allows developers to perform common operations with the MongoDB server such as adding documents, updating documents, deleting documents, or collections.
This article is the first part of CRUD document using MongoTemplate that shares a detailed explanation of inserting document process while insert document with MongoTemplate.
First, we have a new document to be inserted to Mongodb, If the collection of the document does not exist(created) the MongoDB will create the collection first then continue to perform the insert process.
If the inserted document omitted the _id field, the MongoDB driver automatically…
This annotation represents a MongoDB collection. It similars to Entity annotation of Java persistence API. We must be put this annotation at the class level. If the collection’s name different from the class name we can specify the name by using the collection property or value property.
The Field annotation used to represent a field in a collection. It is similar to the Column annotation in java persistence API but it does not have much property like java.persistence.Column
.
Field properties:
Many of us have known about the distributed system, right? It is the kind of software architecture that we distribute the application on multiple servers. It allows us to build high scalability and high reliability. The drawback is managing data consistency becomes more complex. And invalidate cache is one of the complex tasks too. Therefore in this article, I would like to share two caching approaches for a distributed system. Centralized Cache or Localized Cache.
The centralizing cache is mostly done by using cache servers such as Memcached or Redis. …
Software Engineer, Blogger and Amateur Investor.