Class yii\caching\MemCache

Inheritanceyii\caching\MemCache » yii\caching\Cache » yii\base\Component » yii\base\Object
ImplementsArrayAccess, yii\base\Configurable
Available since version2.0
Source Code https://github.com/yiisoft/yii2/blob/master/framework/caching/MemCache.php

MemCache implements a cache application component based on memcache and memcached.

MemCache supports both memcache and memcached. By setting $useMemcached to be true or false, one can let MemCache to use either memcached or memcache, respectively.

MemCache can be configured with a list of memcache servers by settings its $servers property. By default, MemCache assumes there is a memcache server running on localhost at port 11211.

See yii\caching\Cache for common cache operations that MemCache supports.

Note, there is no security measure to protected data in memcache. All data in memcache can be accessed by any process running in the system.

To use MemCache as the cache application component, configure the application as follows,

[
    'components' => [
        'cache' => [
            'class' => 'yii\caching\MemCache',
            'servers' => [
                [
                    'host' => 'server1',
                    'port' => 11211,
                    'weight' => 60,
                ],
                [
                    'host' => 'server2',
                    'port' => 11211,
                    'weight' => 40,
                ],
            ],
        ],
    ],
]

In the above, two memcache servers are used: server1 and server2. You can configure more properties of each server, such as persistand server2g =hljs 1'serppln/span> =hljsitem" h">'span class'="hpln> => [span classppln/span> =hljsitem" h">'sn>, '="hpln> => [span clasclassppln/span> =hljsitem" h">'span>'="hpln> => sppln/span> =hljsitem" h">' servers by settings'="hpln>)span clasclassppln/span> =hljsitem" h">'211 => [span clasclasssss[span clasclasssssclassppln/span> =hljsitem" h">'ljs-'="hpln> => sppln/span> =hljsitem" h">'211)span clasclasssssclassppln/span> =hljsitem" h">'e us'="hpln> => sppln/span> =hljsi> 0)span clasclasssssclassppln/span> =hljsitem" h">'weighs'="hpln> => sppln/span> =hljsi> 5/="hpln>)span clasclasssss])span clasclasssss[span clasclasssssclassppln/span> =hljsitem" h">'ljs-'="hpln> => sppln/span> =hljsitem" h">'211)span clasclasssssclassppln/span> =hljsitem" h">'e us'="hpln> => sppln/span> =hljsi> 0)span clasclasssssclassppln/span> =hljsitem" h">'weighs'="hpln> => sppln/span> =hljsi> 3/="hpln>)span clasclasssss])span clasclas])span clas])span ])s] hed detrinre>rverIdetersabovnd swo Exceptionahe systemtor": serjs-stri>. By saax.htge/memcache" ass' =f="yii-ng-m- "hl

Pub >memcache rver/pecl.php.".Higr/i>

Ma hpmemcache : serjsetting

Ma "ax.ht$behaviorsf="http://pen be configured t, MemCache assumes#$behaviorsnumber">11behaviors

Ma "ax.ht$keyProup-f="http://pen be configured ], #$keyProup-number">11keyProup- tem" h , key soemcachitr2. web-co g"hlally odeterswholrsan>, stor . s < s 11> => 'host'anspan classn be configured gt; number">11tor supp s s 11phe wmca tem" h 11pyii cheIa tem" h /yii-filt s

Ma "ax.ht$ompareValif="http://pen be configured ], #$ompareValinumber">112111nul"s="l|e configu operations that Melangu .blocs. supp"> supp |e configu operations that Melangu .blocs.egularE"> s="l 11211, s Exception<[] =>sure to pr": , anspan classn be configured gt; 60, egularE 'host',ralse,nspan classn be configured gt; 60,ralse tem" h ,ralsen: 'clri>. By saax.htnet/packa ass' =f="yii-ng-m-net/pa"hl

Pub ge/memcach1> rver/pecl.php.".Higr/i>

Ma hme/memcache: serjsetting

Ma "ax.ht__call(8f="http://pen be configured t, Me port 11211#__call(8r">60

See 60truct(8f="http://pen be configured t, Me port 11211#__c/a>truct(8r">60truct(8 tructorn:

See 60

See 60

See 60

See 60

See 60 eith ision, doe. Yot ass="sufth2. key. s < s

Ma "ax.htamts-sBehavior(8f="http://pen be configured t, MemCache assumes#amts-sBehavior(8r">60behaviorire th2. cmemcachen:

Ma "ax.htamts-sBehaviors(8f="http://pen be configured t, MemCache assumes#amts-sBehaviors(8r">60l behaviorsnre thtanCache ass s

Ma "ax.htbehaviors(8f="http://pen be configured t, MemCache assumes#behaviors(8r">60l behaviorsnrcachth2. cmemcache should behav

Ma "ax.htbss="Key(8f="http://pen be configured ], #bss="Key(8r">60nMemC cladsan>, key fromea>given key. s < s

Ma "ax.htcanGet>memcacy(8f="http://pen be configured t, Me port 11211#canGet>memcacy(8r">60memcacy(8 eith ind an whelass=ae end serv"> :

See memcacy(8f="http://pen be configured t, Me port 11211#canSet>memcacy(8r">60memcacy(8 eith ind an whelass=ae end servclas:

See 60

See 60 eith span>ters peccfac hkey frome> < s

Ma "ax.ht/bts-sBehavior(8f="http://pen be configured t, MemCache assumes#/bts-sBehavior(8r">60behaviorifromethtanCache ass s

Ma "ax.ht/bts-sBehaviors(8f="http://pen be configured t, MemCache assumes#/bts-sBehaviors(8r">60

Ma "ax.htenre mBehaviors(8f="http://pen be configured t, MemCache assumes#enre mBehaviors(8r">6060

Ma "ax.hteidats(8f="http://pen be configured ], #eidats(8r">60< s

Ma "ax.htflush(8f="http://pen be configured ], #flush(8r">60< s

Ma "ax.htget(8f="http://pen be configured ], #get(8r">60 eith frome> /span>, peccfac hkey s < s

Ma "ax.htgetBehavior(8f="http://pen be configured t, MemCache assumes#getBehavior(8r">60

Ma "ax.htgetBehaviors(8f="http://pen be configured t, MemCache assumes#getBehaviors(8r">6060'host'60'host' =>sure to pr":

Ma "ax.hthasml">Ln Ln 60Ln eith ind an whelass=tring">'weny eptablenumts-strire thrsalse hets-li s

Ma "ax.hthasHelper(8f="http://pen be configured t, Me port 11211#hasHelper(8r">60 eith ind an whelass=aeme/mem 2. spfin e:

See memcacy(8f="http://pen be configured t, Me port 11211#has>memcacy(8r">60memcacy(8 eith ind an whelass=ae e2. spfin e:

See 60

Ma "ax.htmadd(8f="http://pen be configured ], #madd(8r">6060ters peccfac hkey>": < s

Ma "ax.htm="#(8f="http://pen be configured ], #m="#(8r">606060ters peccfac hkey>": < s

Ma "ax.htmist-S"#(8f="http://pen be configured ], #mist-S"#(8r">6060

Ma "ax.htoff="#Eidats(8f="http://pen be configured ], #off="#Eidats(8r">60'wee> chery/span>, peccfac hkey s < s

Ma "ax.htoff="#G"#(8f="http://pen be configured ], #off="#G"#(8r">60, peccfac hkey s < s

Ma "ax.htoff="#S"#(8f="http://pen be configured ], #off="#S"#(8r">60< s

Ma "ax.htoff="#Ut="#(8f="http://pen be configured ], #off="#Ut="#(8r">60ters peccfac hkey frome> T,i

Note, ther s < s

Ma "ax.hton(8f="http://pen be configured t, MemCache assumes#on(8r">60

Ma "ax.ht="#(8f="http://pen be configured ], #="#(8r">60 eith ision< s 60

Ma "ax.httrigger(8f="http://pen be configured t, MemCache assumes#trigger(8r">60'clri>. By ss' =f="yii-ng-m-net/pa"hl

Propertiesge/memcach1> rver/pecl.php.".Higr/i>

Ma hme/memcache: serjsetting 60 =>poemCo tersan>, peccfac Upadhfng">'host'60 =>poemCo tersan>, peccfac Upadhfng">'host'60 =>poemCo tersan>, peccfac : 60 eith ision, doe. Yot ass="sufth2. key. s

Ma "ax.htaddass="s(8f="http://pen be configured ], #addass="s(8r">60< s 60 eith span>ters peccfac hkey frome> T,iMe cCache: 6060 eith frome> /span>, peccfac hkey s 60ters peccfac hkey>": 60 eith ision60'clri>. By saax.htets-lcka asaax.htc/a>ta-lcka ash1>Pro e.html"cach1> rvs' = -g-m"erjs-strs' =">6060. =glyphic/a glyphic/a-arrow-upka "hpln> e applic.60 =glyphic/a ic/a-hash"a "hpln> e applice applicatioe 'components'. =glyphic/a glyphic/a-penc e applice ape 'components'. =glyphic/a glyphic/a-eye- nsp "hpln> e applic e applic$ort' =">60"> -only<,em> e applice applicatioe"hpln>span e >. By pan es' ="oc'host'. By pan es' =signatureka ppln/span> =signatureespfckapub ="hpln> ppln/span> =signatureebloc"b\ |\ hpln> pljs-str configured gt; 60. By js-strs' =">60number">1he applic. =glyphic/a glyphic/a-arrow-upka "hpln> e applic.number"> titd =glyphic/a ic/a-hash"a "hpln> e applice applicatioe 'components'<#L74/. =glyphic/a glyphic/a-penc e applice ape 'components'<#L74/. =glyphic/a glyphic/a-eye- nsp "hpln> e applic e applic$torplice apeppln/span> =">60span e >. By pan es' ="oc'weight' => 60, i"etrues sserjs-stplic also "s'n cca1s that Memanual,en .settor"s'pan e >. By pan es' =signatureka ppln/span> =signatureespfckapub ="hpln> ppln/span> =signatureebloc"b supp hpln> ">'weight' => number">11tor ppln/styyii-widor: #////BBsp "hpln> ppln/styyii-widor: #//66//">=  "hpln> ppln/styyii-widor: #////BBspnul"s=hpln> >. By js-strs' =">601he applic. =glyphic/a glyphic/a-arrow-upka "hpln> e applic. titd =glyphic/a ic/a-hash"a "hpln> e applice applicatioe 'components'<#L94/. =glyphic/a glyphic/a-penc e applice ape 'components'<#L94/. =glyphic/a glyphic/a-eye- nsp "hpln> e applic e applic$phe wmcaplice apeppln/span> =">60span e >. By pan es' ="oc'weight' => 60, i"etrues sserjs-stplic also n c that Memanual,en .setsaslt-gras <.s'pan e >. By pan es' =signatureka ppln/span> =signatureespfckapub ="hpln> ppln/span> =signatureebloc"b tem" h hpln> ">'weight' => 11phe wmca ppln/styyii-widor: #////BBsp "hpln> ppln/styyii-widor: #//66//">=  "hpln> ppln/styyii-widor: #////BBspnul"s=hpln> >. By js-strs' =">601he applic. =glyphic/a glyphic/a-arrow-upka "hpln> e applic. titd =glyphic/a ic/a-hash"a "hpln> e applice applicatioe 'components'<#L7//. =glyphic/a glyphic/a-penc e applice ape 'components'<#L7//. =glyphic/a glyphic/a-eye- nsp "hpln> e applic e applic$pyii cheIaplice apeppln/span> =">60span e >. By pan es' ="oc'weight' => 60, i"etrues >ters /yii-filana2'espatroy n >tersendthh inii-filt uch /yii-filanc datadhspan>ter slse IDewich sha2'etersslse c/anec-gros sserjs-stplic also truct"s'n cca1s that Memanual,en .c/a>truct"s'pan e >. By pan es' =signatureka ppln/span> =signatureespfckapub ="hpln> ppln/span> =signatureebloc"b tem" h hpln> ">'weight' => 11pyii cheIa ppln/styyii-widor: #////BBsp "hpln> ppln/styyii-widor: #//66//">=  "hpln> ppln/styyii-widor: #////BBspnul"s=hpln> >. By js-strs' =">601he applic. =glyphic/a glyphic/a-arrow-upka "hpln> e applic. titd =glyphic/a ic/a-hash"a "hpln> e applice applicatioe 'components'. =glyphic/a glyphic/a-penc e applice ape 'components'. =glyphic/a glyphic/a-eye- nsp "hpln> e applic e applic$ =">60span e >. By pan es' ="oc. By pan es' =signatureka ppln/span> =signatureespfckapub ="hpln> ppln/span> =signatureebloc"b ">'weight' => Exception<[] hpln> pljs-str configured gt; 60 =signatureespfckapub ="hpln> ppln/span> =signatureebloc"bvoi hpln> pljs-str configured gt; 60 8e">. By js-strs' =">6060. =glyphic/a glyphic/a-arrow-upka "hpln> e applic.60 =glyphic/a ic/a-hash"a "hpln> e applice applicatioe 'components'<#L61/. =glyphic/a glyphic/a-penc e applice ape 'components'<#L61/. =glyphic/a glyphic/a-eye- nsp "hpln> e applic e applic$="hljs-numbeplice apeppln/span> =">60span e >. By pan es' ="oc'host'm wich b'espadn Ife ) m wich b'espadn D anre ": serjs-stplicatioe">. By pan es' =signatureka ppln/span> =signatureespfckapub ="hpln> ppln/span> =signatureebloc"b ">'weigh operations that Melangu .blocs.egularE">egularE hpln> ">'weight' => 60, ppln/styyii-widor: #////BBsp "hpln> ppln/styyii-widor: #//66//">=  "hpln> ppln/styyii-widor: #////BBsp s=hpln> >. By js-strs' =">6060. =glyphic/a glyphic/a-arrow-upka "hpln> e applic.60 =glyphic/a ic/a-hash"a "hpln> e applice applicatioe 'components'<#L9//. =glyphic/a glyphic/a-penc e applice ape 'components'<#L9//. =glyphic/a glyphic/a-eye- nsp "hpln> e applic e applic$="hralseplice apeppln/span> =">60span e >. By pan es' ="oc'weight' => 60, i"etrues sserjs-stplic also n c that Memanual,en .setsaslt-gras <.s'pan e >. By pan es' =signatureka ppln/span> =signatureespfckapub ="hpln> ppln/span> =signatureebloc"b tem" h hpln> ">'weight' => 60,ralse ppln/styyii-widor: #////BBsp "hpln> ppln/styyii-widor: #//66//">=  "hpln> ppln/styyii-widor: #////BBspnul"s=hpln> >. By >. Bysh1>Helpere.html"cach1> rvs' =net/pa-g-m"erjs-strs' =">6060. =glyphic/a glyphic/a-arrow-upka "hpln> e applic.60 =glyphic/a ic/a-hash"a "hpln> e applice applicatioe 'components'<#L063/. =glyphic/a glyphic/a-penc e applice ape 'components'<#L063/. =glyphic/a glyphic/a-eye- nsp "hpln> e applic e applicadd class=s(8 e applic =">60span e >. By pan es' ="oc'host'. By pan eetting 60 =signatureka ppln/span> =signatureespfckapropertie="hpln> ppln/span> =signatureebloc"bvoi hpln> pljs-str configured gt; 60) ppln/styyii-widor: #////BBsp$211 8e"n b: ache applicatioplicatiooooooooooooooooo< ache applicatioplicat = as="-alserwid"> ppln/styyii-widor: #////BBsp$s hpln> s = as="-blocrwid">\ s = as="-spanrwid"> s = as="-alserwid"> ppln/styyii-widor: #////BBsp$211 s = as="-blocrwid"> ">'weight' => Exception<[] = as="-spanrwid"> s 'cl