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黿龠麏齴齟龵龱齼龂齸
龋齂鯺鯶齼龂龪鼪鼧龃龂麏鯫龪鹴龒齸龠鱀鯮鹯麛龦龠鵢鵞鯪鶟龠龋齂龌鰛鯮龵龱龠齴齯龗龕龛龒龎
鳳鳱黽龟鵣麴齂鯧鸸鹿鳿齼龂鶅鶟龪龭鸴齖鸩鸨齴齱龪麳麲鵿麯齴齱齬齩鱀鯮鶞鹾齼龂龠鯥鯡龭鸴鸱鯝鯙齂齀鯗龕鲿鯔麯
麛麲鶃龟鵣麴鴚鴙鶌鹿齴齱鼢鹯麛鴫鯓鰆鹅鯽齜齚龪龵龱齀麏龵龱鴝鷏鸩鸨龪龠鹬麻麹齂齀
齋龅齴齱麳麲龠黆鴚鴙鯒鷵鰏鱳鳅鳃鷮鼸龠齼龂鯏鲿龠齴齱齯龌鯋鲷鲢鲡
鹬鰆鹅龵龱齜齚龟鵣麴齂鯈鯅龭鸴鷮鼸龪鷟鷛龠鯃龟麏鴚鴙鴝鷏鯁鸨鰆鹅鮾鮼龦龠麹麿齀鮻麏齈鱳鯁鸨龪龠鶌鹿麻麹鯒鷵鮺鮷麻齸

本书共65小节:

评论 (写第一个评论)