Li cas Caching System Java (JCS) ua haujlwm?

Txheej txheem cej luam: Nyob rau hauv daim ntawv thov tam sim caching txoj kev loj hlob yog ib qhov tseem ceeb sib nrauj los xam tau tias yog thaum cov ntaub ntawv yog tsim. Lub hom phiaj heev tshaj ntawm caching yog lug txhim khu kev ua tau zoo. Lub cache yuav tau txhais tias yog ib phau ntawm qhov khoom. Nws muaj khoom stateful uas tuav raws li nws tus identifiers. Lub tshaj cia rau tej qhov system caching yog nco qas ntsoov. Tab sis, tus caching uas tau npaj tseg cia khoom hauv disk, database lossis muaj lwm yam pheej cia. Java Caching lawv (JCS) yog ib qhov caching hau distributed tsim nyob rau hauv Java. Nws pab txoj hauv kev kawm ntawv los pab txhawb kom tswj ntau cached ntawv dynamic. JCS kev txhawb hauv nco thiab disk caches. Lub moj khaum JCS yog lub configurable tag los ntawm tej khoom ua ntaub ntawv thov thiab muab ntau rau ntaub cache.

Nyob rau cov tshooj no kuv yuav tham txog lub moj khaum JCS uas ua hauj lwm piv txwv.

Taw qhia: Feem ntau cov kev siv lub, cov ntaub ntawv yog retrieved los ntawm tus database. Lub lag luam database puas kim thiab sij hawm haus mas. Tam sim no ib hnub hauv daim ntaub ntawv hauv web uas muab ntaub ntawv thiab teb thawj zaug yog cov qauv yooj yim kom nws kawm tau zoo. Yog hais tias daim ntawv thov Web site yog toog txheejtxheem database rau txhua qhov kev thov ces nws txoj kev kawm yuav qeeb. Yog li hauv daim ntaub ntawv hauv web tom qab tsim ntau hom kev kawm kev txo sij hawm latency thiab teev.

JCS yog ib puas distributed caching zog uas ua haujlwm rau JDK 1.4 thiab lub versions. Yog qhov kev kawm ntawm JCS impressive tsis muab thiab siab nyeem ntawv.
Nram qab no yog ib co ntawm cov yam ntxwv loj uas Java Caching System
· Nco los xyuas dua
· Xov tswj pas dej ua ke
· Moj khaum extensible
· Configurable runtime tsis
· Qhov tseem ceeb raws li cov ntaub ntawv nqi
· Faib puas cache
· Caij kev tshwm sim yoog

JCS – tus puas Cache: Lub foundation no txog Java Caching System raws puas cache. Muaj plaub hom caches rau cov ib thaj av. Txhua yam uas cache yuav tau xob ua tus JCS configuration mus ua nws lub. Nram qab no yog ntau lub caches plaub thiab cov lus.

  • Nco Cache (LRU): Qhov no yog qhov siv lug sau caching mechanism. Yog lub cim xeeb cache ceev kawg. Nws siv tsawg ntua siv (LRU) algorithm uas tswj cov khoom nyob rau hauv txoj kev nco. Lub LRU nco cache yog xyuas los ntawm nws tus kheej yuav siv daim ntawv qhia LRU. No yuav siv daim ntawv qhia no sai npaum li cas piv rau LRUMap yuav siv los sis lwm hom daim ntawv qhia.
  • Disk Cache (Indexed): Daim disk cache yog siv los muab cov ntaub ntawv thaum muaj daim ntawv qhia txog lub cim xeeb cache. Thaum indexing yog siv rau cov disk cache, txoj kev dlha sai npaum li cas. Queue raws li txoj kev siv los khaws cov ntaub ntawv rau tus disk. Yog daim disk cache configurable kiag li. Xov pas dej ua ke yog siv los tswj tus queue neeg threads uas kuj ua rau tus txheej txheem ceev.
  • JDBC Disk Cache: Qhov no yog lwm yam cache disk yog txhim khu kev qha, ceev thiab mas configurable. Tus sau cia yog JDBC tau tshaj database. Ob lub hauv lub lag luam thiab qhov tseem ceeb yog muab rau tus database. Cov ntaub ntawv no yog muab raws li tus BLOB thiab cov ntaub ntawv DRA hais yog kuj tshem tawm tsis tseg. Xov pas dej ua ke, kuj siv tau uas tswj queue threads neeg ua hauj lwm ceev ua.
  • TCP Lateral Cache: Qhov no yog ib mechanism los faib cov ntaub ntawv rau ntau distributed servers cached. Qhov nov kuj caching zog configurable kiag li. Nws kuj siv tau UDP foundations mechanism ntxiv ntshav tsis puas tabkaum lawv tag nrho. Cov TCP Lateral Cache kom sib txuas nrog lub qhov (socket) servers rau lwm o thiab tej lub hom phiaj cov kev tswj cia. Yog ib tug neeg rau zaub mov txaus uas tswj regions ntau.
  • Tej thaj chaw deb Cache siv RMI: Qhov no yog ib qhov caching los yog JCS. Hauv no mechanism txhua ntawm tsis yuav tsum muab xa mus rau lwm qhov ntawm. Tus neeg rau zaub mov hauv tej thaj chaw deb cache yuav siv li ib qhov zoo sib xws taw tes thiab txhua tus ntawm yuav mus cuag nws. Tus neeg rau zaub mov hauv tej thaj chaw deb cache yog siv los tuav ib serialized version ntawm koj cov kwv. Neeg rau zaub mov tej thaj chaw deb ua grouped nrog lwm servers los rov qab failover.

Quav tshuaj configuration: Nyob rau sab lus no peb yuav tham txog ib daim ntawv thov lus siv JCS. Ua ntej yuav mus ua nws, peb yuav tsum muaj cov dependencies hauv qab no nyob hauv lub CLASSPATH. Thov download tau cov rhawv zeb executable thiab muab cia rau hauv cov CLASSPATH kom lawv muaj lub npe.

  • jcs-1.3.jar
  • commons-logging.jar
  • commons-lang-2.4.jar
  • hwj iav

Ua hauj lwm nrog JCS: Ntawm ntu no peb yuav tham txawv cheebtsam uas Java Caching System thiab configuration kom paub meej. Peb yuav piav ib qho twg uas ua hauj lwm piv txwv.

Nram no yog ib tug yooj yim Neeg ua hauj lwm chav kawm ntawv tuav cov neeg ua hauj lwm paub meej. Cov chav kawm ntawv yuav tsum siv Serializable interface raws li nws cov ntaub ntawv no yuav tsum persisted. Nws muaj txoj kev getter/setter nyeem ntawv thiab sau ntawv.

Listing1: Qhia cov neeg ua hauj lwm kawm

pej xeem hoob kawm ua hauj lwm qiv java.io.Serializable{

lwm lub npe txoj hlua;

qhov chaw nyob txoj hlua;

chaw empid txoj hlua;

neeg ua hauj lwm rau pej xeem(Txoj hlua npe, Chaw nyob txoj hlua, Txoj hlua empid) {

this.name = lub npe;

this.address = chaw nyob;

this.empid = empid;

}

pej xeem txoj hlua getName() {

rov qab los lub npe;

}

pej xeem tsis muaj dabtsis setName(Txoj hlua npe) {

this.name = lub npe;

}

pej xeem txoj hlua getAddress() {

rov qab mus nyob;

}

pej xeem tsis muaj dabtsis setAddress(Chaw nyob txoj hlua) {

this.address = chaw nyob;

}

pej xeem txoj hlua getEmpid() {

rov qab mus empid;

}

pej xeem tsis muaj dabtsis setEmpid(Txoj hlua empid) {

this.empid = empid;

}

}

Hauv qab no yog cov loj EmployeeManager uas imports JCS tej pob khoom siv lub moj khaum APIs. Nws yuav siv ib cheeb tsam cache hu ua 'empCache' tau muab thiab tau txais cov ntaub ntawv mus/los ntawm kev nco. Cov ntaub ntawv yog muab rau lub cache nco thaum uas siv cov yuam sij/tus khub. Tus nqi yog xyuas los ntawm tus yuam sij nrog txhua nrho. Daim ntawv thov no uas qhia ntxiv/nqi thiab tshem tawm ntawm qhov khoom muab rau ib cache.

Listing2: Uas qhia hoob kawm EmployeeManager

ntshuam org.apache.jcs.JCS;

ntshuam org.apache.jcs.access.exception.CacheException;

tsev kawm EmployeeManager {

lwm yam JCS cache;

pej EmployeeManager()

{

sim

{

// Thauj cov cache

cache = JCS.getInstance( “empCache” );

// Initialize lub cache, Nov cov ntaub ntawv yuav tau loaded lub initialization

cache.put( “123”, neeg ua hauj lwm tshiab( “Siav”, “Detroit.USA”, “123” ) );

cache.put( “143”, neeg ua hauj lwm tshiab( “Ric”, “Seattle.USA”, “143” ) );

cache.put( “153”, neeg ua hauj lwm tshiab( “Jhon”, “Chicago.USA”, “153” ) );

cache.put( “163”, neeg ua hauj lwm tshiab( “Dan”, “Houston.USA”, “163” ) );

}

ntes( CacheException e )

{
e.printStackTrace();

}

}

pej xeem tsis muaj dabtsis addEmployee( Neeg ua hauj lwm emp )

{

sim

{

cache.put( emp.getEmpid(), emp );

}

ntes( CacheException e )

{

e.printStackTrace();

}

}

pej xeem neeg ua hauj lwm getEmployee( Txoj hlua empid )

{

rov qab mus ( Neeg ua hauj lwm )cache.Get( empid );

}

pej xeem tsis muaj dabtsis removeEmployee( Txoj hlua empid )

{

sim

{

cache.remove( empid );

}

ntes( CacheException e )

{

e.printStackTrace();

}

}

pej xeem tsis muaj dabtsis loj zoo li qub( Txoj hlua[] args )

{

// Sau cov neeg ua hauj lwm tus thawj tswj

EmployeeManager empManager = EmployeeManager tshiab();

// Ntxiv cov neeg ua hauj lwm rau tus neeg saib xyuas neeg ua hauj lwm

/*empManager.addEmployee(neeg ua hauj lwm tshiab(“Name1”, “address1”, “empid1”));

empManager.addEmployee(neeg ua hauj lwm tshiab(“Name2”, “address2”, “empid2”));

empManager.addEmployee(neeg ua hauj lwm tshiab(“Name3”, “address3”, “empid3”));*/

// Tau txais neeg ua hauj lwm

Neeg ua hauj lwm emp = empManager.getEmployee(“123”);

System.out.println( “Neeg ua hauj lwm txhawb retrieved los cache: ” + emp.getName()+”-“+emp.getAddress());

// Tshem cov neeg ua hauj lwm

empManager.removeEmployee(“123”);

// Tom qab raug tshem tawm ntawm cov neeg ua hauj lwm

System.out.println( “Kev txhawb ua hauj lwm tom qab raug tshem tawm ntawm cache: ” + empManager.getEmployee(“123”) );

}

}

Hauv qab no yog cov ntaub ntawv configuration cache.ccf. Nws tuas txhua lub configurable tsis nrog lawv qhov tseem ceeb. Tus thawj yog vim cache thaj av ntawd uas tuas cov qhov tseem ceeb vim. Yog tias tsis muaj kev cai thaj av configured ces cov kev ntseeg vim yuav muab. Qhov thib ob seem yog defining cache kev cai thaj av ntawd uas yog empCache ntawm no. Nws hais tseg cov kev cai parameter yaam tseem ceeb nuav. Yog NTU CACHE thaj av ntawd uas piav qhov disk cache thiab lwm lwm yam tsis.

Listing3: Qhia ntaub ntawv configuration

# VIM CACHE LAKES

jcs.default=DC

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.default.cacheattributes.UseMemoryShrinker=false

jcs.default.cacheattributes.MaxMemoryIdleTimeSeconds=3600

jcs.default.cacheattributes.ShrinkerIntervalSeconds=60

jcs.default.elementattributes=org.apache.jcs.engine.ElementAttributes

jcs.default.elementattributes.IsEternal=false

jcs.default.elementattributes.MaxLifeSeconds=21600

jcs.default.elementattributes.IdleTime=1800

jcs.default.elementattributes.IsSpool=true

jcs.default.elementattributes.IsRemote=true

jcs.default.elementattributes.IsLateral=true

# CACHE TOS HAIS TSEG REGIONS

jcs.region.empCache = DC

jcs.region.empCache.cacheattributes = org.apache.jcs.engine.CompositeCacheAttributes

jcs.region.empCache.cacheattributes.MaxObjects = 1000 tauj

jcs.region.empCache.cacheattributes.MemoryCacheName = org.apache.jcs.engine.memory.lru.LRUMemoryCache

jcs.region.empCache.cacheattributes.UseMemoryShrinker = cuav

jcs.region.empCache.cacheattributes.MaxMemoryIdleTimeSeconds = 3600

jcs.region.empCache.cacheattributes.ShrinkerIntervalSeconds = 60

jcs.region.empCache.cacheattributes.MaxSpoolPerRun = 500

jcs.region.empCache.elementattributes = org.apache.jcs.engine.ElementAttributes

jcs.region.empCache.elementattributes.IsEternal = cuav

# MUAJ NTU CACHES

jcs.auxiliary.DC = org.apache.jcs.auxiliary.disk.indexed.IndexedDiskCacheFactory

jcs.auxiliary.DC.attributes = org.apache.jcs.auxiliary.disk.indexed.IndexedDiskCacheAttributes

jcs.auxiliary.DC.attributes.DiskPath = c:/temp

jcs.auxiliary.DC.attributes.MaxPurgatorySize = 10000000

jcs.auxiliary.DC.attributes.MaxKeySize = 1000000

jcs.auxiliary.DC.attributes.MaxRecycleBinSize=5000

jcs.auxiliary.DC.attributes.OptimizeAtRemoveCount=300000

jcs.auxiliary.DC.attributes.ShutdownSpoolTimeLimit=60

Xaus: Nyob rau cov tshooj no peb tau tham txog caching tswvyim thiab ib lub nyiam tuaj caching moj khaum hu ua Java Caching uas. Tsab xov xwm kuj them ntau Cheebtsam ntawm JCS thiab lawv yuav siv. Thaum kawg peb tau tham tau ib cov qauv ua piv txwv le Java Caching System moj khaum. Tus JCS yog heev haib thiab sau lus Java. Cov kua mechanism thiab nws nrog tsim mas haib heev rau high nyeem thiab tsis muab daim ntaub ntawv. Qhov kev siv yog kiag li configurable ces nws yuav tau kev nrog rau ib daim ntawv thov tshiab thiab cov uas twb muaj lawm tsis tau muab siv zog npaum.

Tagged: ,
============================================= ============================================== Yuav zoo TechAlpine phau ntawv rau Amazon
============================================== ---------------------------------------------------------------- electrician ct chestnutelectric
error

Txaus siab rau qhov blog? Tshaj tawm lus thov :)

Follow by Email
LinkedIn
LinkedIn
Share