24. 渲染缓存RenderCache

龹龵龲龰龭龹龵龫龩龧龥龡龠龝龛龙龗龥龕龒龹龵龏龎龍龌龉龆龌龃龥龀齽齼齹齵龠齲齱龹龵
齰齮齬齫齪齧齤龫龹龵龏龎齣齡齝龭齚齘龆龌龥齔齒齑齍齪齧齤齉齡齝齹齵齲齱龹龵

齇齄龆龌龃龍龌龫龹龵龲龰齁鼿齄鼽鼼龫龥龹龵龆龌鼺鼸鼴龆龌齝鼳鼲鼯龥龀齽鼿鼽鼼龫龲龰鼮鼫鼪CacheableRenderArray黾黺黹黸黷黳鼲鼯黱黰

$elements = [  
      '#markup' => $elements['#markup'],  
      '#attached' => $elements['#attached'],  
      '#cache' => [  
        'contexts' => $elements['#cache']['contexts'],  
        'tags' => $elements['#cache']['tags'],  
        'max-age' => $elements['#cache']['max-age'],  
      ],  
    ];  

黬黪黺黧齰齇黦黢$elements['#cache']['keys']
鼺鼸齔黆龥黂齁麿麼麻齉麺龆龌麹麷鼲鼯龫龩龧麵麱麭麩麥齡齝龀齽黺
麤麠$elements['#cache_properties']龥黧齁齑齫龲龰龥麕麓龡麺麐龆龌龫齧齤龫麕麏麋齡
麇齔麄Drupal\Core\Render\MainContent\HtmlRenderer::prepare龃齼鹲龀齽龫鹮鹬黺
$main_content['#cache_properties'][] = '#title';
龀龒鹤鹡龹龵龲龰龫'#title'鹝龙齉龭龆龌
黂龀鹛鹚麐黬黪龫齁齔龎$main_content['#cache_properties'][]麤麠龫齇齁鹝龙鹖齁齑齫齪齧齤龫鹓
龒鹒鹏麿鹍齧齤龫'#markup'鼲鼯龥齪齧齤齉鼴龍鹉'#markup'鹝龙鹇黧龫麓
鹃鸿鸾鸻鸷黸黺Drupal\Core\Render::getCacheableRenderArray鸲鹬

麼麻齡齝鹤鹮$elements['#cache']['bin']鸮麠鸪龹龵龏龎龲龰龫龆龌鸨鸦龥齉齡齝齇麤麠
齇麤麠鸣麿鸢黺$elements['#cache']['bin']='render'龥鸞齝龆龌鼺鼸龭龍龌龉龲鸝鸚龫'render'龆龌鸗鹛

麐鸕鸔龆龌鹲鸐齫鸎麐鸍鸌龥鸈龩鸄鸃齼齁鸀鷾鸍鸌黺
$elements['#cache']['max-age']齇鷵鸢0
$elements['#cache']['keys']鸎鷰麐龭鷭鸦
齒鸐鸍鸌鼴麐鹲齑齫齇鷫齘齼齇龕龭龆龌龥齔龎齣鷫齘齼齑麠龕龭龆龌鷪

龹龵龲龰龫龹龵齄鷧龃$elements['#cache']['keys']齁齇鷦鷣鷟鼼龫
黧鹇龹龵龲龰龫$elements['#cache']['contexts']鷝鸈鷚麠龠龆龌id黹Cid)
鷔麱龀鹛齼鷓鸻龠齑齫鷒鷏黺龹龵鹍鷍鸝麿龩龫鸍鸌齡鷊鷉鷓龫Cid鹇龹龵鷆鷊鷉鷓龫Cid齡龗齁齇鸈龫
龡龠鷃鷀鸲鶽龥龀鹛龒龹龵鹍齡鷊鷉鷓龫Cid鼮鼫鼪龹龵鹍Cid",龒龹龵鷆齡鷊鷉鷓龫Cid鼮鼫鼪龹龵鷆Cid"
龹龵鶷鶳龩齪齧齤龫龆龌黆鼳鶲鶮鶫鶧鶣黆齍龥鶢鶡鶞鸢#lazy_builder鶮鶫鶙鶕龥齉齡龗龭齑鶒鶑鶐鷵鶏鶋
鸞齝麄龹龵鶷鶉齰齇鶇鶄龹龵鷆龫龆龌黆鼳鶲龥齉齼齇鶇鶄龹龵鷆Cid龥齔齒齑齍齼鶂鹲鵾鹬鵼鶑龆龌龫龲鸝

鷔麵麱鵺鷚鵹麥drupal鹤鹮龠鵵齲龆龌黹Two-tier caching黰龥鵮鼮鼫龆龌齲麠鵪鵦鵢龥鹃鸿齔鼳黺
龹龵鵡鷫鷆龍龌龆龌龲鸝龩龥鵞鵝龆龌黆鼳鶲齁鵚鹲鷟鼼龥齔龎鶂鹲鷟鼼龥鷔麱龹龵鹍鷆龫Cid齁齑齽龫龥鶂鹲鵙麱鷒鷏龥鵕鵔龒龲鸝龍龌龉龀齫cid鼳麋齡
齔龎鹲鷟鼼龥鵓鷊鷉鷓龹龵鷆龫龆龌齧龲鸝龲龰龥麹龃黦鵑'keys'鹇'bin'
齒鵐鵏鵋齑齫'#cache_redirect'鹝龙龥麹麓齇龡NULL龥鼺鼸鷭鸦龡true
鴿鷆龒龀齫龹龵鷆龫龆龌齧龲鸝龲龰黹黬黪齇齁龹龵鷆龫龲龰黰龍龌龉龹龵鹍Cid鼳龥鴻鷫齑齫齲麠鵪龆龌
龀齫齲麠鵪龆龌鴹鴸龫tags鴵max-age鹇龹龵鷆龫龆龌齧龲鸝齑鴱
麄鴯鵼龆龌龲鸝龩龥齔龎鴮鸻鷭鸦龠'#cache_redirect'鵓鴪鴧齁齑齫齲麠鵪龆龌龥鷔麱鴤齄鹡龉龫龲鸝鴢鴞get龆龌龥鼿齄鸐鴜龆龌鴙鴖鹡龉龹龵鷆鼲鼯

思考:

龗鵚龒龹龵鷆龫龏龎鵕鵔龍龌麄龹龵鹍Cid鼳鵹麥龡鵙麱麥
齔龎龀齽鼫龥鷔麱麄鴕鴑麹黧鴏鸲麐鴌龀鴋龆龌鸕鸔鴈鴅龩龥鷔麱齼鹚麐鶇鶄黧龹龵鹍龫Cid龥龀齡龗齁齫鷒鷏
龆龌API龫齑鳿鳼鵓齁黺龭龆龌龫龲鸝鴌鳸鸮鳵龆龌鹝龙龲鸝龥齡齝鳳龹龵鷆龫龹龵龲龰鸮鴸鷊鷉鷓鴌鳰龫龆龌id

龆龌齲麠鵪龫鼪鳮鳫鳩鷒鷏黾黺
鳧鳦鹲龀齽齑齫龹龵龲龰黺

- A (#cache['keys'] = ['foo'])   
-- B (#cache['contexts'] = ['b'])  
--- C (#cache['contexts'] = ['c'])  
--- D (#cache['contexts'] = ['d'])  

麄A鴜鳗鹲鶂鹲麤麠黆鼳鶲鴌龀齫鷒鷏鶂鹲鳔鳐龥龀鹛鳍麠鶂鹲麤麠黆鼳鶲
B齁A龫齪齧齤龥C鴵D齁B龫齪齧齤龥黂C鴵D鼴龗鷍鸝B龫黆鼳鶲麓龥鳊鳉齑龫龌麄齑齫
鹃鸿鳅齼齁黺B龫黆鼳鶲'b' = 'b1'龩鳁鹲齪齧齤C龥'b' = 'b2'龩鳁鹲齪齧齤D
齒龩鲼齫龹龵龲龰龫龏龎鵼鷚鸢B鴜鳗麤麠龫黆鼳鶲b龫麓龥黆鼳鶲b鹇齧齤龫鴌鳰鲹鴕鷫龡齑齫鲷鸦鲵龥鲳鲷鸦鲵鷫龡鲰鲬鳔鳐龉鲼齫A龫鹲鲨龙
麄龀齽龫鲦鲥鼳鲢鲢龆龌齲麠鵪龕鴮鲞鵙麱黺
麿'b' = 'b1'龩黺A龫龹龵鹍Cid龡鼪foo黾 鼲鼯麤鵪bc
麿'b' = 'b2'龩黺A龫龹龵鹍Cid龡鼪foo黾 鼲鼯麤鵪bd
鸐齫鲜鲘龫齇鸈鼲鼯龹龵龲龰龫龹龵鹍Cid鲖鲕龠龥齔龎麄龹龵龲龰龃齇鲒鵋鲑鵐龫鲰鲬齍鸿鸻黧麻龫黱鲎鷟鼼龥龀鹛龒鳳龆龌鵼鶑鲌鲉龫龲鸝
齔龎鲒鸌鲰鲬龲鸝龥麇齔龀鹛齔龎鷭鸦黆鼳鶲b鹇鲷鸦鲵鷫龡鲰鲬龥麷麻龕鲅鲃鲂鱾龆龌鹲鲨龙龥鸞齝鵼鶑齍龫龲鸝齇龕鹲鲌
黂齁麄龀齽龫鲦鲥鼳龥鱼鴿鶂鹲鲌龥黂龆龌鱺黂鶂鹲鱶鱳鷊鷉龥鱰鷫龡龠鱬鱨龥麄b龫齇鸈黆鼳鶲鲜鲘龃龕齇鱥鷭鸦龆龌
齼鱤齁麄鱡龃龫鱠鱟鱜龀鱛龥鷔鱛鱙鱕龥鱟鱜鷔鱛龩龀鱛鵮鱙鱕龥鶢鱤鳮鳫鳩鸐鱒鱎龥龀齼齁鲳鷒鷏麏鱊龫鶞齍
龡龠鵺鷚龀齫鷒鷏龥鴕鴑鸾鸻龠齑鱆鸲鹬龥齹齵鱂鰿龫鴌龹龵鹍cid龫鼲鼯鸕鸔鶏鶋龥鼴鶏鶋龹龵鷆Cid龫鼲鼯
齼齁鰻龹龵鹍Cid麄鰹鲜鲘鰵鰲鰰鰭鰫鸞鹲龫黆鼳鶲龥鴙鴖龍龌鸞鹲龫黆鼳鶲龥鴻鷫齑齫鰪麠麤鵪
麤鵪龫鼲鼯齼齁龹龵鷆Cid龫鼲鼯龥龀齫鼲鼯齁龕鱂鰿鷭鸦龫龥鴤齄鲰鲬齍龍鰦鰣鲃龙

鷣鰠鰝鷧鰜鶐鰘麄鷊鷉鰕鰔鰑龃鹲鸐鸌鰍鲦麇鰌鰈鰅黺龆龌鹇鰁麏
齔龎鰀齇龗麩鵺黆鯼龫鼲鼯龥齡齝鯹鯷鼳龥麄鷆鯼鹲鹃鸿龹龵龲龰龫鯴齪鷆鯰鶑齄鱛齍鲢龥鯮鯮鸿龕龆龌黆鼳鶲鹇鲰鲬鯭鰵龫鯬鯪鲹鴕
麄鸮麠鸪龫龹龵龲龰龃麐鯩鲎黬黪黆鷀鳮鳫鳩鷒鷏鯨鱕龫鯥麄鲌鲉

占位渲染缓存:

麄drupal鸾鯤龫鹤鹮龃龥龹龵龆龌鯣鹮龫齁鯡鸨龹龵龆龌PlaceholderingRenderCache黧鯠鸀龠RenderCache龫鯞龗
麼麻鶇鶄龹龵鯡鸨鯝龫鯙龫齼齁龒鴕鴑齇鯖鯒龆龌龫鼲鼯齚齘鷓齍龥鯑齚龹龵龥龏龎齰齇龕龆龌
鷔麱麄齑齫鯐鯼龃龀齽龫鼲鼯鷓鸻鰠鯎龥鶞鸢鶂鹲龆龌龥鸞齝鹚麐鰠鯎龹龵龥龀齁鶂鹲鸎麐龫
鸞齝龡龠鵺鷚龀齫鷒鷏龥鯍鶕龠鼪鯡鸨龹龵龆龌PlaceholderingRenderCache黾龥麄龀齫龹龵龆龌龃
龒齇鯖鯒龆龌龫鼲鼯龍龌麄鯉龫鹝龙龃龥鰠鯎鹚麐龩龥鵕鵔鯇鶑龥龒齇龕鯰鯎龹龵龥龀齼龝龛龠龙龗
鳧鳦黺龡鵙麱齇鯃鸞鹲鳳龆龌鵼鶑龫龲鸝齣鸕鸔龀齽龫麭麩鵹麥龀齽齹齵鰠鯎鶐鹮龆龌龥鯁鮽龲鸝鸚鮺鮸齇齁鮵龛鲨鮴麥
麐麩鵺龡鵙麱鴕鴑鶂鹲龀齽鼫鹚麐鴧鮳鯡鸨鯝齧齤龫龹龵齁麄龹龵鴙鷆鸕鸔龫龥鹖麹麷齇齁
齔龎龀齽麭麩龥麿鴕鴑鮱鷧鯨鱕鲰鲬鷟鼼龥龆龌鮰鲨龥龀齽齼龕鮬鲞鲌鲉
鹖鯡鸨龹龵齧齤龡鵙麱齇鮩鮥龲鸝鷟鼼龫鷒鷏龥鮤龡麄鴕鴑鴙鷆鮣鸔鯡鸨鮢鮟龩龥麷麻齁鮞麄齑鱕鮣鸔龫龥鶂鹲麹麷鮱鷧鮜鮘麹龃

本书共83小节:

评论 (写第一个评论)