JCs initialization 1

Source: Internet
Author: User

Start: if you are not clear about the basic concepts and terms in JCs, please refer to the relevant documents first.

1. First, let's look at the inheritance structure of the class JCs:

 

(1)
The cacheaccess class annotation is written to this class provides an interface for all types of access to the cache. This class provides the operation interface for caching. This class contains two members:

LPrivatestaticCompositecachemanagerCachemgr;

/** Cachemanagerusebythevariousformsofdefineregionandgetaccess * is used to manage and obtain the cacheaccess object of region.

*/

Compositecachemanager: manages various cache domains (managesacompositecache. thisprovidesaccesstocachesandistheprimarywaytoshutdownthe cachingsystemasawhole .)

 

 

 

LProtectedCompositecache <K, V> cachecontrol;

/**

* Thecachethatagiveninstanceofthisclassprovidesaccessto.

*

* This is the map that actually stores the key-value pair. The put and get operations are all about it.

*/

Compositecache is the core class for managing a domain (thisistheprimaryhubforasinglecache/region. itcontrolstheflowofitemsthroughthe cache. theaupoliciaryandmemorycachesarepluggedinhere .).

 

(2)
Groupcacheaccess: access for groups. (do not understand this)

 

(3)
JCs class

This is a basic class for using the JCS system and provides operation interfaces for domains. A cache domain should correspond to a JCs instance.

(4)
JCs Initialization

Use the static method getinstance () to get an instance.

 

/**

* Getajcswhichaccessestheprovidedregion.

* <P>

*@ ParamRegionregionthatreturnjcswillprovideaccessto

*@ ReturnAjcswhichprovidesaccesstoagivenregion.

*@ ExceptionCacheexception

*/

Publicstatic<KExtends
Serializable, VExtendsSerializable> JCs <K, V> getinstance (string Region)

ThrowsCacheexception

{

Compositecache <K, V> cache =Getcachemanager(). Getcache (region );

ReturnnewJCs <K, V> (cache );

}

 

First, use the getcachemanager () method to obtain a compositecachemanager instance,

ProtectedstaticCompositecachemanager getcachemanager ()Throws
Cacheexception

{

Synchronized(JCs.Class)

{

If(Cachemgr=Null
)

{

If(Configprops! =Null
)

{

Cachemgr= Compositecachemanager.Getunconfiguredinstance();

Cachemgr. Configure (Configprops
);

}

Elseif(Configfilename
! =Null)

{

Cachemgr= Compositecachemanager.Getunconfiguredinstance();

Cachemgr. Configure (Configfilename);

}

Else

{

Cachemgr= Compositecachemanager.Getinstance();

}

}

 

ReturnCachemgr;

}

}

The default configuration file of JCS is cache. CCF, this file should be located in the compositecachemanager class package, and JCs provides two methods for customizing the configuration file: setconfigfilename and setconfigproperties. The two definitions are used in getcachemanager () to initialize compositecachemanager, two methods are provided to define the configuration file: Properties and file path. When using the file path, note that the file should be placed under the package of the compositecachemanager class. In this case, the file name is directly used, or put it in a path under SRC, and then access the file through "/file path" (this is the way to read the inputstream of the file when using the file path)
Is = getclass (). getresourceasstream (propfile )).

The following describes how to load the configuration file and obtain the cache instance.

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.