7. 缓存系统Cache

龹龸龶drupal8龛龚龗龔龓龒龏龍龊龇龄龁齿龚龗龔龓龛齼齸齵齴齱齮龚龗龛龗龹齫齩齥齢齠齝龛齜齙齗齕齑齏齎齌齋齉齮齈齅齃鼿齢鼼鼻鼹龚龗鼶鼳龗龹龛鼱鼯齮鼮龁齠鼫鼧鼥鼯鼤鼠鼝鼜鼚鼖鼔鼒鼐齃齮鼏鼍鼌齅鼈鼆鼃鼂黿黾黻龚龗鼫鼧黹黸齙齗鼝鼜鼖黵齮龚龗龛黱龁齠鼫鼧齮鼿齠鼫鼧黹黸龗黰龹黬黨黧黦黥黤黡黟黝黜黚默黔齮黑鼏鼤龁黏齎齌黍黋齋齉齮龹齌黍黋黊黈黄龚龗黁黀麼鼯齮drupal8龛龚龗麸鼚麶黱麲麰鼿齢齠齝龛鼏麸鼚麯

Symfony鼶鼳齎麜龚龗麘麖齮drupal8麓麏麍麉黟黝龇龚龗龔龓齮druapl8龛龚龗龔龓齅麅黱龚龗麂鹿鹽黡齮鼍鹻龚龗鹺黬龔龓黄鹸鹴鹱齮鹰鹮鹭黥鹩鹨鹴鹱鹧鹣鹠鹴鹱鹧鹞鹛鹴鹱鹘鹘齮鹔鹑鼐鼳鼱鼯龚龗龛鹴鹱鼍鹐黹黸龚龗齮鹍鹌龛鼍鹋鼻 鹴鹱鹊 鹇龗黰龚龗鹴鹱鹆鹃鸿鸾鹧鸽鼤鸺鸸麖鹘鹍鹌齅鼤鼠鹴鹱鹊鸴龗鸱齮龹鹴鹱鹊黄黸cache_鸥龒鸤龛鹴鹱鸣默龗黰龛黱龚龗鹴鹱齮鸢鸞鼳龁齠鸚鸗cachetags龛鹴鹱鸣鼻鹇鸴龗龚龗龔龓龛鸎鸊鹴鹱齮鼮鸆鸄鸁鷿龚龗龛鷾鷻鸁鷸鷷龍鷵黹齮鷳鷯cachetags鸣齮鹮鼧麅鸁鷸鷭龁齠龚龗鸣鼹齅鼯鸁鷿cachetags鸣齮鸁鷿cachetags鸣鼈鷬鷨鷤鼳龚龗鸣鷣黡龛鹴鹱鷠鷟鹆鷞鷠鷟鼏鷝齮齅鼈鷬鷨龔龓鷚鷘鸱齮鼮龔龓鷔鼠鷾鹸鷒鷑鷾鼈鷍黝龚龗龔龓鷉鷈鷅黬鹴鹱齮黑鼏鷄鷁龚龗鷟鶾齮黹黸鸁鷸鷷龍龁齿麯

drupal8龛龚龗龔龓黹黸鼤鼠黬鶽鶼鶺龚龗鹴鹱齮齅鷞鷞黱鹴鹱鹊齮鹻黹黸鼫鶶鹣鹠鸞鶲齌齋龚龗鹘鹘齮齿黡龸龶鼍龛黟黝鶰鷿齜

龹鷿龄drupal8龚龗龔龓鷾鶭鶩鶦鼍黟黝龇齢鼝鶤鶣鹭齮龁黱鹮鶢龗鸴鶠鶜鶛鹴鹱鹧鸽黱鹮鶢鶘鶗龚龗鹴鹱黱鶓鷒鶐齵黹龚龗齱齸麯

鶌齥鹮鶢龗鸴鶠鶜鶛鹴鹱drupal8鼳齢齠鶋鶈齜 cache_bin cache.backend

bin黹黸鷿龄鸥龗黰鹴鹱龛鵹鵷鹧鹭黥鹧鹴鹱鵶鹘鹘齮鹰鹮龹鹍鹌黟黝黄鹴鹱鹊龛龁齠龚龗鸣鵳黱龁齠bin,鼿齠鸣鵳黱龁齠鵹鵷齮鷣黡黱龁鵮龁鵮龛鹴鹱麯backend鵳黱bin龛鵭鼼鵪齮鼍黱龁齠鵦鵤齮黜鵡鸴龗鹧鵠鵝鹧鶜鶛鹧鷠鷟bin鷣黡龛鹴鹱齮鸥鵛黻鶜龇backend鼿黻齠鵘鵕齮鵒鵏黱鵌鵋龛鵊鵇齮鼍鵅鵦齥龒鵋龚龗鼏鷝鹆龚龗鵁鷿黧黦黥鹧鴾鴻黥龚龗鹘鸱齮龹龔龓鷣黡鴹齠bin鵦鹿鴶龁齠backend齮鼿鶽鵦鹿鶌龔黹黸龹黈鴴鹣鹠鸸麖settings.php鷣黡麸鹠鹆齿黡鴱鸱齮鴭鹣鹠龛鴩鴧齿鴦鼻鹍鹌鹣鹠齮麅鼥鼯鴤bin鴢鴡龚龗鴝鴜鵳鼒麍鸄鼐齃backend

鶌齥鹮鶢鶘鶗龚龗鹴鹱黱鶓鷒鶐齵黹龚龗齱齸鼳鴚齠鶋鶈齜 CacheMaxAge CacheTags CacheContexts
CacheMaxAge 齜鵁鸣龚龗鴋鼝鼳鷟鷾鷑
CacheTags 齜龚龗鴉鴆鵁鸣龚龗龛鹴鹱黱鵛黻
CacheContexts 齜龚龗黤齿鸸鵁鸣鴅龁鹴鹱龹齅鴅鴩鴧齿龛鴂鳿齮黤齿鸸鼝黬鹇麍鶭鳼鵦鵤鹆鳺齅黱麏鶲鸱齮鹰鹮鶭鳼龛鳸鳵鹧鹴鹱鳲鶺鹧鼻鳮鵁鷿鹧鼻鳮鹧ip鹧cookie鹴鹱鹘鹘齮鴅龁鹴鹱龹鼿鳬黤齿鸸齿黹黸鸣黝鳪齅鴅龛鴂鳿麯
龔龓鹩鹨龇龁齠黹龚龗齫齩鳧鳥鹮鼧龁齠鹴鹱黱黹龚龗龛齮黾黻黹黸鳢鼐黟黝鳞鳧鳥龛黹龚龗鳜鹴鹱齮鷣黡鹩鹨龇黸黤鴚齠鶋鶈龛鳙麯


齿黡鳗龁鳗鳕鸾鵁鳓黟黝齜


drupal8鳐鳍Cache龔龓龹 \core\lib\Drupal\Core\Cache 齮鼍齎麜鴋鳐鳍龛鳄鼒齮麜鳂鷷龚龗鳀鶤齏鼥鼯鹋鼻龚龗龛鲿鶼鹋鼻麯
鷤鼳龛backend鹐鼥鼯黟黝 CacheBackendInterface 鳧鳥齮鸢鳧鳥鷣黡鹩鹨龇 backend 黹鼻龛鲷鼻鶼鲵鹆龹drupal8鷣黡鷤鼳龛鲱鵘鹐鼳鲯鹩鲭鼹齮鳧鳥黸Interface鼫鲬齮齴鲫黸Trait鼫鲬齮鴝鴜鶼鲵黸Factory鼫鲬齮龁齠鸸麖龁齠鲨齮鸸麖鵘鶠鲨鵘龁鷨齮鷤黸鹔黹黸鲥鹱鸸麖鵘鼝鷨鲤鶗鸸麖龛鼻鲣齮鼂黬鲯鹩鲭鼹鶭鳗鲟鲝鸸鲙鸱齮鲘齥鳧鳥龛鲖麖麸鼚黱鼝鲔鲖麖麸鼚龛鲑鲏鲍龁齮鼻鳮齅鼥鼯鲌鲋鳕鸾黟黝齮鲇鵦鳧鳥齎麜龛鶼鲵鹋鼻鷵黹麯

drupal8鹍鹌齎麜龇黸齿Backend齜

Apcu4Backend ApcuBackend DatabaseBackend MemoryBackend MemoryCounterBackend NullBackend PhpBackend

鸢鸞鼳齢齠齴鱼龛Backend齜

BackendChain 鴤黬齠Backend鼫鶶齈鹇鹋鼻齮鱺鱷龁齠Backend鱴

ChainedFastBackend 鸥龇鱳鱰齱鼒鴤龁齠鱯齋Backend齏龁齠龁鱬Backend鼫鶶齈鹇鹋鼻

黸黤 Backend 鹐鱪 Backend 鴝鴜黜鵡黟鱩鱥鹆 BackendChain 鵝鸞鸱齮鹍鹌鹩鹨龛 Backend 鴝鴜鼳齜

ApcuBackendFactory ChainedFastBackendFactory DatabaseBackendFactory MemoryBackendFactory NullBackendFactory PhpBackendFactory

鼿鳬鴝鴜鹐黟黝龇 CacheFactoryInterface 鳧鳥齮鳞鳧鳥鱣鱠鱝齮鷞鷞鹩鹨龇龁齠get鶼鲵鳧鱛bin鱘鹴齮鼍鱗鶛Backend鵦鵤齮鹍鹌龛bin齏Backend鼳龁鱕鵦鹿鶌龔齮鹮鶢麍鹩鹨鼿鶽鶌龔鵕鱒龹黈鴴鹣鹠鸸麖settings.php鷣黡鹩鹨鷵黹齮鳲鶺鹮齿齜

$settings['cache']['bins']['鹔鹩鹨龛bin']="龚龗鴝鴜黧黦龛黧黦ID";

鹍鹌龛鵦鹿鶌龔鹩鹨龹CacheFactory鲨龛get鶼鲵鷣黡齮齑鵁鳓鰿鰻鰷鶣鹭鲝齜

鼿鷣鳗龁鳗鹋鼻鴋黬龛DatabaseBackend齮鼍黱鹍鹌Backend齮黜鵡鹴鹱鹊龚龗鵭鼼齮龹DatabaseBackend鲨鷣黡鹩鹨龇鹴鹱鹊龚龗bin龛鹴鹱鼫鰳齮龊鳗龁鳗鹍鹌龛鹴鹱鹊龚龗鸣齮鼍龍鹐黸cache_鸥龒鸤齮鸣鰱鰰鹮齿齜

cid 齜龚龗id齮龁齠255黸鶣龛ascii鰱鰪鰦

data 齜龚龗龛鹴鹱鶣鹭

expire 齜龚龗齃鶐鷾鹸鰣齮鰢鰟鸥-1

created 齜龚龗鰔鰑龛鷾鹸

serialized 齜龚龗龛鹴鹱黱鶓鰌鷒鰊鰆鱥

tags 齜龚龗鴉鴆

checksum 齜龚龗鹴鹱鼳鷟齱鰂鯾鳙

public function get($bin) {  
    $cache_settings = $this->settings->get('cache');  
    if (isset($cache_settings['bins'][$bin])) {  
      $service_name = $cache_settings['bins'][$bin];  
    }  
    elseif (isset($cache_settings['default'])) {  
      $service_name = $cache_settings['default'];  
    }  
    elseif (isset($this->defaultBinBackends[$bin])) {  
      $service_name = $this->defaultBinBackends[$bin];  
    }  
    else {  
      $service_name = 'cache.backend.database';  
    }  
    return $this->container->get($service_name)->get($bin);  
  }  

龹龒黡龏龍鯼齃龇鶌齥鹮鶢鶘鶗龚龗鹴鹱黱鶓鷒鶐鼳鴚齠鶋鶈齮黾黻龔龓龹鼿齠鹴鹱鸣鼫鰳鷣黡鹮鶢鯺鯹鳪鹇鵕鱒鵦鹿鶌龔鹮齿齜

cid鵦鹿鴶黤齿鸸齫齩齮齅鴅龛黤齿鸸麘鶶鼐齃龛龚龗cid齅龁鯶齮鹋鼻黄龛cid齏龚龗bin鷣黡龗鸴龛cid齅龁鯶齮龗鸴龛cid黱鰌鷒鯵鯱鹘鶼鲵鯮鯫鼐齃龛龁齠255黸鶣龛ascii鰱鰪鰦齮鯮鯫鷒鯨鰿鰻鰷鶣鹭鲝齜

鹋鼻黄龛cid黱鱪 CacheContexts 龚龗黤齿鸸麘鶶鼐齃


expire鵦鹿鴶鷾鹸齫齩齮鯤鯠鷒鶐龛鷾鹸齮鼿齠鱠鱝齅鼱黬鴱麯


tags鵦鹿鴶鹴鹱鶽鲨齫齩齮龁鵮龚龗黹鼒鱪黬齠鴉鴆鵦鹿龛鹴鹱麘鱷齮鳂黄鯟鶢龁齠tag鵦鹿龛鹴鹱鷍鯜鯚鱥鹐鼈鯘鱷鳞鵮龚龗鷠鷟齮鴹龁齠tag鵦鹿龛鹴鹱鼌黹鼒鯖黬鵮龚龗鹋鼻齮黾黻鼮tag鵦鹿龛鹴鹱鷍鯜鯚鱥鷾龏龍鹮鶢齵鷾鼐鲌鼿鳬龚龗鵮齝鷒鶐龇鵕鱒鼿黱drupal8龚龗麸鼚龛龁齠鲑鯒齮鯏鯌鵳龹齥checksum鼳鷟齱鰂鯾鳙齮黤鸸鯼鷒龔龓黄龗龹龁齠龚龗鸎鸊鹴鹱鸣齮鸣鵘鯋黱cachetags齮鷣黡鼳齢齠鰱鰰齜鴉鴆齵鷠鷟鯈鹴齮鴹鼮龁齠鴉鴆鵦鹿龛鹴鹱鯇鯜鯆鱳鸄鼼齮黾黻鷠鷟鰱鰰鵳鼈鯄龁齮鼏checksum龛鳙鵳黱鳞鵮龚龗鷤鼳鴉鴆鵦鹿龛鷠鷟鰱鰰鳙鲍齏齮麶鵳黱鯼鯟鵊龁齠tag鵦鹿龛鹴鹱麅鼯鯇鯜鯆鱳鸄鼼齮黾黻鵳鼈鯁齈鹋鼻齃鼍龛龚龗鰂鯾鳙鯚鱥齮龔龓鵳黹黸鲥鹱鼿齠鹇鶘鶗龚龗黱鶓鷠鷟齮鼿齠鼚鼖鰂鯾鳙齏鶘鶗龛鴝鼼黱鱪DatabaseCacheTagsChecksum鲨鹇麓鱷龛齮鼍鼚鼖鳪鼮龒鰂鯾鳙鮾齏龚龗bin鷣黡龛鰂鯾鳙鹰鮺齮齅鴅鼹龚龗鷠鷟齮鮷鮷鹰鷠鷟龛鰂鯾鳙鼝齮鹮鼧龚龗龛鹴鹱鴭鴉鴆鼹鰂鯾鳙鰢鮳鸥0麯


鹴鹱鹊bin鷣黡鴹齠鵮齝鵳黱龁齠龚龗齮drupal8鹻鱣鮫鳍龛鸥龏龍鸗龇鼤龁黏龛鴝鼼齮龹龁齠龚龗鵮齝鷣黡鸴龗鱣鼝龛龁齠鹴鹱鮩齮鹴鹱鮩黸鹴麘龛鶼鶺鸴龗龹龚龗bin龛data鰱鰰齮鵦鼿齠鹴鹱鮩龛鵭鼼drupal8齎麜龇 CacheCollector 鲨齮鼍黟黝 CacheCollectorInterface , DestructableInterface 鳧鳥齮 Destructable 鳧鳥鼻齥黧黦龹鮧鮦鷾鸗龁鳬鮤鲬鴝鼼齮鲨鮡齥鮟鰳鮝鹴麯


黸黤鵳黱鹴鹱鹊龚龗龛鹴鹱鼫鰳齵龗鶜鴩鴧齮齿黡鹇鳗龁鳗鹴鹱龛黹龚龗齱齜


鼥鼯龚龗龛鹴鹱鵦鵤鯖鮛鮚龇黹龚龗鳜鹴鹱鵦鵤齮黾黻鼍鵳鳕鮘龇黹龚龗齱齮黹龚龗鳜鹴鹱鵦鵤黟黝龇黹龚龗齫齩鳧鳥齜 CacheableDependencyInterface 齮鳞鳧鳥鷣黡鷞鷞鹩鹨龇鴚齠get鶼鲵齮鮔鮐鵦鹿齥黤齿鸸鹧鴉鴆鹧鷒鶐鷾鹸齮鼳龇鼿鳬鶼鲵鵳黹黸鲌鲋鼥鼯龚龗龛鹴鹱鵦鵤鹮鶢龚龗齮 CacheMaxAge CacheTags CacheContexts 麶鯋鲍鸥黹龚龗鮍齱齮 CacheTags CacheContexts 鹐黱鰱鰪鰦鸣鯠麯龹鯟鶢黊黈龔龓黄黹龚龗鹴鹱默鼳鼿鴚鶼黡龛齫齩麯
\core\lib\Drupal\Core\Cache\Context 黄鹩鹨龇黀鼻龛黤齿鸸齫齩麯

protected function normalizeCid($cid) {  
   // Nothing to do if the ID is a US ASCII string of 255 characters or less.  
   $cid_is_ascii = mb_check_encoding($cid, 'ASCII');  
   if (strlen($cid) <= 255 && $cid_is_ascii) {  
     return $cid;  
   }  
   // Return a string that uses as much as possible of the original cache ID  
   // with the hash appended.  
   $hash = Crypt::hashBase64($cid);  
   if (!$cid_is_ascii) {  
     return $hash;  
   }  
   return substr($cid, 0, 255 - strlen($hash)) . $hash;  
 }  

黸黤鵳黱drupal8龚龗龔龓龛鳐鳍齮齿黡龸龶齢齠鹿鼻鳐鳍龚龗鳄鼒龛鳀鶤齮鷷龍黱 Page Cache Dynamic Page Cache 齮鼍龍鹐黱龔龓鹍鹌齎麜龛鳀鶤齮鮋齅黹鶌鮈齮鮆齥 core\modules 齮龹龔龓鮂鷿鵌黨-鹞鹛齜鳀鶤鰆鸣黄鼒鮁齃麯


Page Cache鳀鶤鸥魾鵘鼻鳮齎麜鹽黡龚龗齮龹龏龒黡鷍龛魻 HttpKernel魶魵 魲鷣黡鼳齎齃齮鼍黟黝龇 HttpKernelInterface 鳧鳥齮鮍齥http黄鹸麖齮龚龗龛鹴鹱鮆齥鹴鹱鹊鸣 cache_render 鷣黡齮鹋鼻URI齏鶭鳼鳲鶺鼼鸥cid齮鼿齠鳀鶤龛bin鵳黱render齮Backend黱DatabaseBackend麯


Dynamic Page Cache鳀鶤鸥鯟鵊鼻鳮齎麜鸄鳿龛龚龗鹽黡齮鹴鹱鸴龗齥鹴鹱鹊 cache_dynamic_page_cache 鸣齮鼍魫鷒鹋鼻魪麖魨魦魣鸺龹龹鸄鳿麂鹿鯇鯜鷾龚龗鹴鹱齮鶌齥魪麖魨魦魡鶭鶐魞鵌魛魗魕龔鰆魓魐麯


鹮鼧鹔鳗齃鼿鷣齮鹔鹿鳞鷝鰌鼝鷨龇龄龇drupal8龛龚龗鷔鼼魣鸺齮魏魌鵳黱魉魆魂鶐齮鬿鼝鬻齙鬸鱯鬶齮鬲鼖鬯龹齙龒鳪龇鼿鬫魓魐齮鼳齅魏鲿鶼鬨鬥鬢鳵麯

本书共71小节:

评论 (写第一个评论)