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龞龝龜鷍鼿魝鸿齷魍魉鵥黳魈魄魁鶁齷鬿鼡鬽齝鬼鱕鬹齷鬸鼚鬷龹齝龗鳕龌齃鬳魒魏齷鼴齈魍鲬鶲鬰鬮鬪鳟麨

本书共63小节:

评论 (写第一个评论)