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.