Use the Java cache mechanism to create faster web applications-Overview and Configuration

Source: Internet
Author: User


Web developers can use the Java cache function to conveniently and quickly improve the performance of applications. For Java applications, a powerful distributed Java cache system (JCs) is a tool that can be highly configured with simple APIs. This article outlines JCs and shows how to use it to speed up Web applications.

 

Many desktop applications are being rewritten into web applications. Ideally, the overwritten applications should be as fast and scalable as those of the desktop version. Almost all web applications can greatly improve the speed through JCs. Regular caching of data that rarely changes is a good way to reduce user wait time. Using simple APIs to process cached data can help us achieve this goal. Open-source JCs (Apache
This document explains how to configure and use JCs to cache data for Web applications.

 

JCs Overview

 

JCS is a cache system written in Java that can be used to create desktop and Web applications. It provides a convenient mechanism for processing.

The metadata stores data in the cache;

The token retrieves data from the cache;

・ Deletes data from the cache.

Using JCs, you can save cached data to different data storage regions. JCs defines four types of core storage areas: memory, disk, lateral, and remote. We can use these core storage areas together for greater flexibility in cache data. For example, you can specify the storage region to be used first and use another storage region when the cache fails.

 

Memory Zone

The memory region is
Recently used) when the pure memory cache area of the operation rule is filled up in the memory cache area, LRU first deletes the least recently used cache data. This data zone has a better execution efficiency. Therefore, most users specify it as the cache zone first used by default.

 

Disk Area

The disk area is a cache data area on the file disk of the Web server. To improve performance, you can save the cached data key (KEYS) in the memory and cache the actual data on the file disk. In a typical JCs configuration, any data that cannot be held in the memory is written to the disk area.

 

Lateral Zone

The lateral cache area provides a way to allocate cached data to multiple horizontally associated servers. The cache server must open a port for listening and establish a socket link. Because this storage area does not guarantee data consistency between caches, this becomes a potential problem. However, if you want to design and use this storage area, this issue is unlikely to happen.

 

Remote Area

Remote use of RMI (Remote Method
Invocation) provides a cache zone. This storage area uses a remote server that processes cached data. The remote Cache Server can be used by multiple JCs client applications to save cached data. The listener is used to collect requests from clients and servers. This cache area helps ease the serialization and multi-link overhead.

 

JCs Configuration

The JCs configuration process is as simple as creating and compiling a cache. CCF file. The cache. CCF file defines the cache area to be used and the attributes or options of these cache areas. To combine this file into an application, you need a convenient and quick way to scale the cache. The following is a simple example made to display the main configuration points. You can specify many options and configurations to adapt to the correct configurations you need.

The most basic cache. CFF file-a pure memory cache Configuration

JCs. Default = JCs. Default. cacheattributes = org. Apache. JCs. Engine. compositecacheattributes

JCs. Default. cacheattributes. maxobjects = 1000

JCs. Default. cacheattributes. memorycachename =

Org. Apache. JCs. Engine. Memory. LRU. lrumemorycache

 

In the above configuration, the last row specifies the lrumemorycache as the memory cache, and the number of objects in the memory is set to 1000.

 

The cache system of most applications requires more extensive configuration than the preceding configuration. In the following configuration, the memory zone is used and the disk zone is used when you define your own storage zone.

 

JCs. Default = disk_region

JCs. Default. cacheattributes = org. Apache. JCs. Engine. compositecacheattributes

JCs. Default. cacheattributes. maxobjects = 1000

JCs. Default. cacheattributes. memorycachename =

 
Org. Apache. JCs. Engine. Memory. LRU. lrumemorycache

 

JCs. region. our_region = disk_region

JCs. region. our_region.cacheattributes = org. Apache. JCs. Engine. compositecacheattributes

JCs. region. our_region.cacheattributes.maxobjects = 1000

JCs. region. our_region.cacheattributes.memorycachename =

 
Org. Apache. JCs. Engine. Memory. LRU. lrumemorycache

JCs. region. our_region.cacheattributes.usememoryshrinker = true

JCs. region. our_region.cacheattributes.maxmemoryidletimeseconds = 3600

JCs. region. our_region.cacheattributes.shrinkerintervalseconds = 60

JCs. region. our_region.cacheattributes.maxspoolperrun = 500

JCs. region. our_region.elementattributes = org. Apache. JCs. Engine. elementattributes

JCs. region. our_region.elementattributes.iseternal = false

 

JCs. Auxiliary. disk_region = org. Apache. JCs. Auxiliary. disk. Indexed. indexeddiskcachefactory

JCs. Auxiliary. disk_region.attributes =

 
Org. Apache. JCs. Auxiliary. disk. Indexed. indexeddiskcacheattributes

JCs. Auxiliary. disk_region.attributes.diskpath = C:/JCs/disk_region

JCs. Auxiliary. disk_region.attributes.maxkeysize = 100000

 

In the configuration above, set disk_region to the default storage zone. Disk_region is of the indexeddiskcachefactory type and specifies that the cached files should be stored in the C:/JCs/disk_region directory on the disk. The second group in the above configuration defines its own storage area and adds some options for it. This configuration that specifies both the memory area and the disk area is a common type. In the above configuration, a backup zone is defined in the third group.

 

JCs has a dependency: concurrent and commons-logging (in JCs 1.2.7 In the layout before. 0, there is another dependency: commos-collections and commons-lang)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.