|
|
Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs
Enterprise Java specialist Steve Haines joins the Open source Java projects series this month with an introduction to Java Caching System (JCS), a robust enterprise-level caching solution. Steve starts with a quick introduction to caching, discussing the criteria for determining if objects should be cached and whether your application would benefit from a cache. He then shows you how to configure JCS and use it to build a caching application.
The Java Caching System (JCS) is a robust open source caching product released through the Apache Jakarta subproject. It provides the standard features that you would expect of a cache system, such as in-memory caching and algorithms for selectively removing objects from the cache. It also offers more-advanced features, such as indexed disk caching and support for distributed caches.
A JCS cache has a map-like structure in which data is stored in the cache as a name-and-value pair. JCS partitions the cache into regions. Each region has its own configuration as well as its own set of name-value pairs. Each region can:
The keys (the names in the name-and-value pairs) in one region can be the same as keys in other regions. This is important because it enables you to maintain separate caches for different objects all within the same JVM -- and all defined in a single properties file.
Each of the open source Java projects covered in this series is subject to a license, which you should understand before integrating the project with your own projects. JCS is subject to the Apache License; see Resources to learn more.
This article explores JCS by first showing you how to obtain and install the current release. I'll then explain what a cache is, why you might use one, and whether or not it is the right solution for a specific application. Next, you'll delve into the JCS properties file, which is the best route to understanding JCS. Finally, you'll build a sample caching application that uses JCS.
You can download JCS from the downloads page of the JCS project site. As of this writing, the latest version is 1.3. Download the binary distribution (either as a TAR file on Unix systems or a ZIP file on Windows) and decompress it to a local directory on your computer.
The root of the installation directory contains jcs-1.3.jar, which you must add to your CLASSPATH before compiling and running a JCS applications.
Throughout this article, as well as in your own independent studies, you'll find that the JCS docs directory is an invaluable resource for information about JCS, including the API documentation. The robust Javadoc document is your authority for understanding how to use JCS classes.
You will need two dependencies:
Commons LoggingConcurrentFrom Commons Logging, add commons-logging.jar to your CLASSPATH.
A cache is designed to hold objects, typically in memory, for immediate access by an application. An application interacts differently with a cache from the way it interacts with external storage solutions. Typically, an application obtains a connection to a database, executes a query across a network, and parses the results as they are returned. A cache maintains a collection of readily available objects in a robust map-like structure that does not require a network call. Enterprise Java application performance improves exponentially when it accesses reusable objects in a cache after loading them from a database, rather than making remote database calls.
More from JavaWorld