Implementing Caching in Spring REST Services

Introduction Here I am going to show an example on implementing caching in Spring REST web services. Caching is used to store copies of frequently accessed data in several places for the request-response path. In other words, it stores a copy of a given resource and serves it back when requested. The performance of web sites and applications can be significantly improved by reusing previously fetched resources. Caching in REST services reduce latency and network traffic and thus lessen the time needed to display a representation of a resource. By…

Continue

Introduction to JCache JSR 107

Caching libraries such as Ehcache, Hazelcast, Infinispan, GridGain, Apache Ignite in the Java ecosystem are common and indeed is needed in many different kinds of solutions to optimize the application in various ways. The simplest libraries are just in-memory object maps with simple evict rules, while the most advanced caching libraries have efficient cross-JVM features and configurable options to write the cache state to disk, and a good basis for memory heavy computation.

Continue

EhCache Implementation using Spring Boot Framework

In this tutorial I am going to explain you how to use EhCache in application with Spring Boot framework. Caching mechanism improves application’s performance by loading the repeated data from the cache instead of fetching it from persistent storage, thus reducing the network round trips. The terms “buffer” and “cache” tend to be used interchangeably; note however they represent different things. A buffer is used traditionally as an intermediate temporary store for data between a fast and a slow entity. As one party would have to wait for the other…

Continue

LRU Cache implementation in Java

A cache is an amount of faster memory used to improve data access by storing portions of a data set the whole of which is slower to access. Sometimes the total data set are not actually stored at all; instead, each data item is calculated as necessary, in which case the cache stores results from the calculations. When we need a datum then first we check the cache if it contains the required datum. If it exists, the datum is used from the cache, without having to access the main…

Continue

Precached images using JavaScript

Images often take several extra time to download from a Web server. If images change in response to user actions then you may want the same fast response that users are accustomed to. It may be an irritating situation while users are waiting for image(s) to be downloaded for a page and the page is loading slowly due to such images. JavaScript comes to rescue in this situation by enabling scripts to load images into the browser’s memory cache without displaying the image instantly, a technique called precaching images. In…

Continue

Second level EHCache example in Hibernate 5

Introduction This tutorial will show second level ehcache example in Hibernate 5. EH stands for Easy Hibernate. We know that there are three types of caching mechanism such as First Level – session, Second Level – SessionFactory and Query Level – SessionFactory. Caching mechanism improves the performance of application because the data are loaded from cache instead of hitting the database again. For more information on First Level, Second Level and Query Level please go through Hibernate Caching strategy.

Continue

How to disable Browser Cache easily in CodeIgniter 3

Introduction In this tutorial I am going to show you how to disable browser cache easily in PHP based web framework Codeigniter. It is a good idea to cache static data on browser but it may be a problem when browsers cache dynamic data. For example, when browsers cache session data. Though generally you destroy session but still using browser’s back button users are able to view some data on browser because browser stores data into its cache. For example, when users logged in to application they can easily go…

Continue

Different types of cache strategies in Hibernate

Introduction In this tutorial I will tell you different types of caches in Hibernate framework. Hibernate is an ORM (Object Relational Mapping) framework. Hibernate uses two different caches for objects: first-level cache and second-level cache. If you have queries that run over and over, with the same parameters, query caching provides performance gains. Caching introduces overhead in the area of transactional processing. For example, if you cache results of a query against an object, Hibernate needs to keep track of whether any changes have been committed against the object, and…

Continue