Using Java Distributed Cache to Scale Java Applications

Java is very popular for developing high traffic enterprise level applications with a requirement to use a java distributed cache. These may be Java Web applications, Java web services, or other Java server type applications. A wide range of these applications belong to Online Transaction Processing (OLTP) category involving millions of transactions.

You can handle this high transaction load by adding more web/app servers at the application tier but you cannot do the same at the database tier. The most you can do is buy more expensive hardware for your database server, but that only takes you so far. Therefore, the database always becomes a bottleneck and slows down your Java applications and may even grind it to a halt if too much load is put on it.

Database Scalability Problem in High Traffic Applications

Database Scalability Problem in High Traffic Applications

Figure 1: Database Scalability Problem in High Traffic Applications

So, what to do about this? Well, Java Distributed Cache has become quite popular for handling such situations. It lets you cache application data in memory and reduce those expensive database trips that are overwhelming your database server.  Unlike a database, a Java Distributed Cache can scale linearly by letting you add more servers at run time as you need to handle greater transaction loads. This ensures that your Java Cache never becomes a scalability bottleneck.

Java Distributed Cache also lets you store your Java WebSession or Servlet Session in it. These sessions are then replicated in a multi-server environment so you don’t lose any session data if a cache server ever goes down. Plus, Java Cache is a much faster and more scalable session persistence store than your JSP Servlet container like Tomcat or JBoss.

TayzGrid is an in-memory data grid and a Java Distributed Cache for Java applications. It is extremely fast and scalable and provides linear scalability to you.

Below is an example of using TayzGrid from Java Application:

import com.alachisoft.TayzGrid.web.caching.Cache;
import com.alachisoft.TayzGrid.runtime.*;

public class MyCachingSample {
    private String url = "dbc:msql://";

    public Employee GetEmployee(String empId) throws Exception {
        Employee emp = null;
        try {
            Cache cache = TayzGrid.initializeCache("MyDistributedCache");
            emp = (Employee) cache.get(empId);
            //If key not found in cache, Load from the database
            if (emp == null) {
                //Your logic goes here
                ResultSet rs = stmt.executeQuery("SELECT * FROM Employee WHERE EmpId ='" + empId + "'");
                if ( {
                    emp = new Employee();
                    emp.EmpId = rs.getString("EmpId");

                    //Cache key for future use
                    cache.insert(empId, emp, null, Cache.NoAbsoluteExpiration, Cache.NoSlidingExpiration, CacheItemPriority.Default);
        } catch (Exception exp) {
            throw exp;
        //return the required object
        return emp;

TayzGrid supports the industry standard JCache API (JSR 107) so you are not locked into a proprietary caching solution. It also provides powerful GUI based and command-line configuration and monitoring tools. This makes TayzGrid management very simple.
Please download a fully working copy of  TayzGrid Enterprise and try it out for yourself.


About Iqbal Khan
Iqbal Khan is the president and technology evangelist of Alachisoft - a leading provider of TayzGrid (an In-memory Data Grid) and NCache (an In-Memory Distributed Cache for .NET)
This entry was posted in Java Distributed Cache and tagged . Bookmark the permalink.

2 Responses to Using Java Distributed Cache to Scale Java Applications

  1. Pingback: Using Hibernate Second Level Cache with TayzGrid - TayzGrid

  2. Pingback: Using Hibernate Second Level Cache with TayzGrid - Alachisoft

Leave a Reply

Your email address will not be published. Required fields are marked *