Thứ Bảy, 18 tháng 2, 2023

which feature i should use caching like redis

 

You should consider using a caching service like Redis in your Spring Boot application when you have data that is frequently accessed and doesn't change frequently. Here are some common scenarios where caching can be beneficial:

  1. Read-heavy applications: If your application has more reads than writes, caching can help to reduce the load on your backend systems and improve the response time for read requests.

  2. Performance-critical applications: If your application requires high performance, caching can help to reduce the response time for frequently accessed data and improve the overall performance of your application.

  3. Applications with a large user base: If your application has a large user base, caching can help to reduce the load on your backend systems and improve the scalability of your application.

  4. Resource-intensive operations: If your application performs resource-intensive operations, such as complex calculations or data processing, caching can help to reduce the time required to perform these operations and improve the performance of your application.

  5. Applications with a high concurrency: If your application needs to handle a large number of concurrent users or requests, caching can help to improve the response time for these requests and reduce the load on your backend systems.

In summary, caching can be beneficial in a variety of scenarios where fast and efficient access to data is required. If your Spring Boot application meets one or more of these scenarios, you should consider using a caching service like Redis to improve the overall performance and scalability of your application.

Thứ Hai, 10 tháng 9, 2018

Understanding Injection

Some definition first, until now I've used the term component when talking about the classes we've been developing. The term is not completely accurate. I should have used instead the term bean for our book repository. A bean is just an object that is managed by the Java EE runtime or container. With a broader view, we can say that in Java EE we have objects that are managed by containers. In fact, in Java EE every object is a bean. Well, I should say, most objects are beans. Most objects are beans except for JPA entities. The difference between a class and a bean is that the container gives a bean extra services such as lifecycle management, interception or injection. In terms of code, a bean is just a concrete Java class with a default constructor. Here the BookRepository class doesn't implement anyspecific interface nor it extends a specific class. It can have any annotation and can define any method. In fact, with very few exception, potentially every Java class with a default constructor is a bean in Java EE. So our BookRepository is considered a bean. But why should we care about knowing the difference between a simple class and a bean? Well because now we can use extra container services, one of them being injection. But what is injection? Applications are made of business logic, interaction with modules, user interface, external APIs and so on. In fact, in an object oriented programming language, like Java, all these can be summarized by objects depend on other objects or let's say beans depend on other beans. But instead of having beans creating their own dependencies, they can delegate these tasks to the container. This is what's called inversion of control. The control of choosing the dependency is inverted because it's given to an external container. The Java EE specification taking care of dependency injection is called CDI, or Context and Dependency Injection. CDI is built on the concept of loose coupling, strong typing. Meaning that beans are loosely coupled, but in a strongly typed way. The container's job is to inject references into these loosely coupled beans. CDI does much more than just injection and I would recommendattending the Pluralsight course dedicated to CDI. CDI decoupling goes further by bringing interceptors, decorators, events and context management to these beans. But that's not the purpose of this course. Let's see how to implement injection.

Chủ Nhật, 2 tháng 9, 2018

Đồ đạc sinh viên

Đầu tiên thì bạn phải làm quen với việc buid set đồ từ đôi giày buid lên. Bạn phải chọn giày đầu tiên rồi mới đến quần áo :D. Mình thấy nhiều bạn mua quần áo thì hiệu này hiệu kia nhưng lại phối với 1 đôi giày dở hơi (giày lười 150k vỉa hè, dép sandals v.v.v.) nên nhìn rất dở hơi và không đâu vào đâu cả.
Nếu bạn muốn ăn mặc trẻ trung năng động thì đầu tiên là tống hết những đôi giày lười rẻ tiền đi và thay vào đó là sneakers. Mình thấy bạn có 1 đôi stansmith rồi - khá ổn và an toàn, phối được với nhiều thể loại, thường thường nên có 1 đôi an toàn ntn (tham khảo các đôi tương tự như vans olskool, converse v.v.v).
Về quần thì mình đoán là bạn đang mặc quần chợ và không thử kĩ nên trông có vẻ lùng nhùng và hơi quá size. Lẽ ra quần thì mình thường thích quần Chinos (kaki) hơn nhưng mình thấy đùi bạn có vẻ to to :sweat::sweat: nên tốt hơn hết là mặc jeans slimfit và nhớ đi chọn cẩn thận để có dáng ôm vừa vặn. Sinh viên thì mua quần tầm 6-800k là oke, tránh mua jeans đen hoàn toàn vì dễ phai màu, mặc vài lần là bạc màu à - suggest là nên mua màu chàm(indigo).:adore::adore:
Áo thì khỏi nói :sweat::sweat: có vẻ là cái áo này bạn mua hàng chợ ~200k, nhìn nó rất dở hơi và nói thật là hơi quê, hơn nữa áo sơ mi trắng trơn chỉ đẹp khi bạn mặc cùng quần tây, sơ vin và là áo phẳng phiu thôi. Mình nghĩ là bạn nên chuyển sang mua T-shirt thì ổn hơn, mua print hoặc trơn đều được nhưng nếu muốn trẻ trung hơn tí thì mua print sẽ tốt hơn, thời tiết mùa thu thì có thể thêm flannel. Còn mua áo sơ mi thì nên mua loại kẻ (caro, sọc v.v.v) và vải tốt hơn tí chứ không phải loại vải trơn lèo nhèo như kia thì nhìn nhăn nheo rất chán đời. và nếu mùa thu mặc sơ mi thì có thể mặc thêm cadigan, nhìn rất hàn quốc và cool :adore::adore:
Về phụ kiện, tốt hơn hết sinh viên các bạn thì đeo balo, hoặc nếu đeo túi chéo thì tránh các loại túi đeo chéo ~150k hàng chợ vì nhìn nó khá là trẻ trâu. Mua hẳn 1 cái túi da ~ 1 củ, bền, đẹp lại thơm nữa. Nói luôn về đồng hồ, thường người ta đeo đồng hồ để khoe và là điểm nhấn của set. Mình không giải thích được tại sao các bạn lại đeo đồng hồ fake < 1-2 củ để nhằm mục đích gì. Nếu cảm thấy trống tay thì bạn có thể tham khảo các loại Bracelets bạc hoặc tràng hạt, vòng tay chứ đừng đeo đồng hồ fake nếu bạn thật sự muốn đầu tư cho ăn mặc :stick::stick:

Hình tham khảo search bừa trên mạng :byebye::byebye::byebye:
source: (Thắc mắc) ra đường thấy ai cũng mặc đồ đẹp, nhìn lại mình thì..

Thứ Ba, 24 tháng 7, 2018

WEB-INF bảo mật

Những tập tin jsp trong thư mục WEB-INF không thể truy cập trực tiếp bằng cách gõ vào thanh địa chỉ trình duyệt được mà chỉ có thể truy cập bằng cách response.sendRedirect hoặc Dispatcher.foward

Java static method, khi nào nên sử dụng?

Phương thức static:

Nên tự hỏi: "Liệu việc tạo phương thức này có ý nghĩa gì không nếu obj chưa được xây dựng?". Nếu có, phương thức đó nên được xác định là static.
Ví dụ:
Bạn có lớp Car, và bạn có method "double convertKmphToMps(double kmph)" (Chuyển đổi từ km/h sang m/s) nên là static. Bởi vì ai đó chỉ muốn biết 1 km/h sang m/s là bao nhiêu, chứ họ không quan tâm đến việc xây dựng hay khởi tạo một chiếc xe.
Tuy nhiên "void setColor(String color)" (phương thức set màu sắc cho chiếc xe cho một chiếc xe cụ thể) không thể là static được bởi vì ta không thể gọi phương thức này khi chưa có một chiếc xe cụ thể nào được xây dựng (it's inconceivable to call the method before any Car has been constructed).