Welcome!

Weblogic Authors: Yeshim Deniz, Elizabeth White, Michael Meiner, Michael Bushong, Avi Rosenthal

Related Topics: Weblogic

Weblogic: Article

Implementing a Cluster-Aware Cache Using WebLogic

A lazily reconstructable cache system that notifies cluster members of deletes

Caching information on the WebLogic tier can significantly increase performance and reduce the number of external system calls needed for data retrieval. This is especially true when an application wants to store bits of information that rarely change, such as a list of countries or catalog entries. Nowadays, memory is so cheap that application architectures can benefit from caching data on the Web/EJB tiers.

This is not a new concept; most developers already do this. Whether it's accessing data from a simple java.util.Hashtable or java.util.Hashmap, or using a sophisticated LRU cache mechanism (a derivative of LinkedList), there is minimal overhead in accessing information. The real question isn't how the data is cached or what mechanism is used for storage, but how to preserve the data's integrity and notify cluster members of changes in a highly available, clustered environment.

For example, suppose you're building an e-commerce storefront application that sells clothing. The product information such as the item name, description, SKU, price, and image can be stored in memory on the application tier. The benefit of storing the data in memory is faster page loading and a reduction in database calls.

Now, what happens when your business user wants to change the price or description of the catalog item? How would you notify all of the members of the cluster of this "delta" change? Remember, you probably still want the data to be stored in memory if possible for performance reasons. Also, you probably want the information to be updated in close real-time and don't want to reload all of the data if it hasn't changed.

This article illustrates a simple technique for implementing a "lazily reconstructable" cache system that notifies cluster members of invalidations (deletes).

For example, look at the following code:


static Hashtable cache = new Hashtable();

public Product getProduct(String productID) {
Product product = (Product) cache.get(productID);
if (product == null) {
// get the product from the database
product = ProductDAO.getProduct(productID);
cache.put(productID, product);
}
return product;
}
A simple java.util.Hashtable stores the list of products indexed by the product identifier in a static cache. Products are retrieved from the database and added to the cache lazily if they don't already exist. This code snippet demonstrates how to retrieve a product by looking into cache and grabbing it if it doesn't exist.

What happens if a product description changes for a specific product? Look at this code:


public void changeDescription(String productID, String newDescription)
throws ProductNotFoundException {

ProductDAO.changeDescription(productID, newDescription);

Command command = new InvalidateCacheCommand(productID);
ClusterNotifier.notify(command);
}
The code behind the ProductDAO.changeDescription method updates the product ID in the database with the new description. The ClusterNotifier.notify method (see Listing 2) will delete the product from the local cache and send an invalidation event to the cluster members to delete the product from its local cache. Once this is done, all of the members in the cluster will have the product removed from memory. If a user requests this product on any node, it becomes lazily initialized with the new description that was set. See the snippet below from getProduct() example:

if (product == null) {
// get the product from the database
product = ProductDAO.getProduct(productID);
cache.put(productID, product);
}
This will reinitialize the product from the database and insert the information back into cache.

How does this work? Well, let's take a look.

Deep Dive into the Classes
Note: This article uses unpublished private APIs from WebLogic. They work with WebLogic 7.x and 8.x, but there's no guarantee they'll be supported in future versions. Many of the underlying details were "introspected" by putting the WebLogic.jar in the classpath of the IDE.

Command Interface (Generic)
First, let's take a look at the Command interface. It's simple. It defines a single method called "execute."


public interface Command extends Serializable {
public void execute();
}
The Command interface is used to do the work that needs to be done in the cluster. Notice that it is Serializable. It contains the logic to do a task when it reaches each cluster member. This interface is generic enough to do any operation. This article discusses how this interface can be used to invalidate keys in a cache across the cluster.

InvalidateCacheCommand Concrete Implementation (Specific)
The class in Listing 1 is a concrete implementation of the Command interface to invalidate the keys in a cache. Notice that the execute method clears the entry of a statically bound cache. How does this work?

More Stories By Bahar Limaye

Bahar Limaye is a system architect at The College Board. He has extensive experience building distributed object-oriented systems.

Comments (1) View Comments

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


Most Recent Comments
wesnur 12/10/09 06:07:00 AM EST

Hi Bahar,

I do agree with you that cluster caching is the way to overcome issues like Scalability and Reliability. Data synchronization is no longer a big problem if you have dynamic cluster cache is your app. Along with yours, I have found some other good reads about Cluster Cache as well. One of them is Benefits of using NCache Dynamic Clustering Capabilities . I am sure this read‘ll further clear the doubts of the readers of your article, If they have any.

@ThingsExpo Stories
SYS-CON Events announced today that Calligo, an innovative cloud service provider offering mid-sized companies the highest levels of data privacy and security, has been named "Bronze Sponsor" of SYS-CON's 21st International Cloud Expo ®, which will take place on Oct 31 - Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Calligo offers unparalleled application performance guarantees, commercial flexibility and a personalised support service from its globally located cloud plat...
IoT is at the core or many Digital Transformation initiatives with the goal of re-inventing a company's business model. We all agree that collecting relevant IoT data will result in massive amounts of data needing to be stored. However, with the rapid development of IoT devices and ongoing business model transformation, we are not able to predict the volume and growth of IoT data. And with the lack of IoT history, traditional methods of IT and infrastructure planning based on the past do not app...
With tough new regulations coming to Europe on data privacy in May 2018, Calligo will explain why in reality the effect is global and transforms how you consider critical data. EU GDPR fundamentally rewrites the rules for cloud, Big Data and IoT. In his session at 21st Cloud Expo, Adam Ryan, Vice President and General Manager EMEA at Calligo, will examine the regulations and provide insight on how it affects technology, challenges the established rules and will usher in new levels of diligence...
SYS-CON Events announced today that DXWorldExpo has been named “Global Sponsor” of SYS-CON's 21st International Cloud Expo, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Digital Transformation is the key issue driving the global enterprise IT business. Digital Transformation is most prominent among Global 2000 enterprises and government institutions.
SYS-CON Events announced today that Datera, that offers a radically new data management architecture, has been named "Exhibitor" of SYS-CON's 21st International Cloud Expo ®, which will take place on Oct 31 - Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Datera is transforming the traditional datacenter model through modern cloud simplicity. The technology industry is at another major inflection point. The rise of mobile, the Internet of Things, data storage and Big...
In his session at @ThingsExpo, Sudarshan Krishnamurthi, a Senior Manager, Business Strategy, at Cisco Systems, discussed how IT and operational technology (OT) work together, as opposed to being in separate siloes as once was traditional. Attendees learned how to fully leverage the power of IoT in their organization by bringing the two sides together and bridging the communication gap. He also looked at what good leadership must entail in order to accomplish this, and how IT managers can be the ...
DX World EXPO, LLC., a Lighthouse Point, Florida-based startup trade show producer and the creator of "DXWorldEXPO® - Digital Transformation Conference & Expo" has announced its executive management team. The team is headed by Levent Selamoglu, who has been named CEO. "Now is the time for a truly global DX event, to bring together the leading minds from the technology world in a conversation about Digital Transformation," he said in making the announcement.
Everything run by electricity will eventually be connected to the Internet. Get ahead of the Internet of Things revolution and join Akvelon expert and IoT industry leader, Sergey Grebnov, in his session at @ThingsExpo, for an educational dive into the world of managing your home, workplace and all the devices they contain with the power of machine-based AI and intelligent Bot services for a completely streamlined experience.
In the enterprise today, connected IoT devices are everywhere – both inside and outside corporate environments. The need to identify, manage, control and secure a quickly growing web of connections and outside devices is making the already challenging task of security even more important, and onerous. In his session at @ThingsExpo, Rich Boyer, CISO and Chief Architect for Security at NTT i3, discussed new ways of thinking and the approaches needed to address the emerging challenges of security i...
While the focus and objectives of IoT initiatives are many and diverse, they all share a few common attributes, and one of those is the network. Commonly, that network includes the Internet, over which there isn't any real control for performance and availability. Or is there? The current state of the art for Big Data analytics, as applied to network telemetry, offers new opportunities for improving and assuring operational integrity. In his session at @ThingsExpo, Jim Frey, Vice President of S...
"DX encompasses the continuing technology revolution, and is addressing society's most important issues throughout the entire $78 trillion 21st-century global economy," said Roger Strukhoff, Conference Chair. "DX World Expo has organized these issues along 10 tracks with more than 150 of the world's top speakers coming to Istanbul to help change the world."
"We provide IoT solutions. We provide the most compatible solutions for many applications. Our solutions are industry agnostic and also protocol agnostic," explained Richard Han, Head of Sales and Marketing and Engineering at Systena America, in this SYS-CON.tv interview at @ThingsExpo, held June 6-8, 2017, at the Javits Center in New York City, NY.
"We are focused on SAP running in the clouds, to make this super easy because we believe in the tremendous value of those powerful worlds - SAP and the cloud," explained Frank Stienhans, CTO of Ocean9, Inc., in this SYS-CON.tv interview at 20th Cloud Expo, held June 6-8, 2017, at the Javits Center in New York City, NY.
"We've been engaging with a lot of customers including Panasonic, we've been involved with Cisco and now we're working with the U.S. government - the Department of Homeland Security," explained Peter Jung, Chief Product Officer at Pulzze Systems, in this SYS-CON.tv interview at @ThingsExpo, held June 6-8, 2017, at the Javits Center in New York City, NY.
The financial services market is one of the most data-driven industries in the world, yet it’s bogged down by legacy CPU technologies that simply can’t keep up with the task of querying and visualizing billions of records. In his session at 20th Cloud Expo, Karthik Lalithraj, a Principal Solutions Architect at Kinetica, discussed how the advent of advanced in-database analytics on the GPU makes it possible to run sophisticated data science workloads on the same database that is housing the rich...
Internet of @ThingsExpo, taking place October 31 - November 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA, is co-located with 21st Cloud Expo and will feature technical sessions from a rock star conference faculty and the leading industry players in the world. The Internet of Things (IoT) is the most profound change in personal and enterprise IT since the creation of the Worldwide Web more than 20 years ago. All major researchers estimate there will be tens of billions devic...
What sort of WebRTC based applications can we expect to see over the next year and beyond? One way to predict development trends is to see what sorts of applications startups are building. In his session at @ThingsExpo, Arin Sime, founder of WebRTC.ventures, discussed the current and likely future trends in WebRTC application development based on real requests for custom applications from real customers, as well as other public sources of information.
"The Striim platform is a full end-to-end streaming integration and analytics platform that is middleware that covers a lot of different use cases," explained Steve Wilkes, Founder and CTO at Striim, in this SYS-CON.tv interview at 20th Cloud Expo, held June 6-8, 2017, at the Javits Center in New York City, NY.
SYS-CON Events announced today that Massive Networks will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Massive Networks mission is simple. To help your business operate seamlessly with fast, reliable, and secure internet and network solutions. Improve your customer's experience with outstanding connections to your cloud.
"MobiDev is a Ukraine-based software development company. We do mobile development, and we're specialists in that. But we do full stack software development for entrepreneurs, for emerging companies, and for enterprise ventures," explained Alan Winters, U.S. Head of Business Development at MobiDev, in this SYS-CON.tv interview at 20th Cloud Expo, held June 6-8, 2017, at the Javits Center in New York City, NY.