Implementing Caching in Spring REST Services

Introduction Here we are going to see an example on implementing caching in Spring REST 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 making…

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 framework

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 affecting performance, the buffer alleviates this by allowing entire blocks of data to move at once rather then in small chunks. The data is written and read only once from the buffer. Furthermore, the buffers are visible to at least one party which is aware…

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

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 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. First-level cache: is associated with the Session object, while second-level cache is associated with the SessionFactory object. By default, Hibernate uses first-level cache on a per-transaction basis. Hibernate uses this cache mainly to reduce the number of SQL queries it needs to generate within a given transaction.

Continue