Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 295807

Decouple cache implementation from the renderer and expose as renderCache service

$
0
0

Problem/Motivation

Anything that caches data as part of the render pipeline needs to properly support:

- Cache Contexts
- Cache Tags
- Max Age
- Attached Assets
- Rendered Markup
- #cache_redirect (and placeholders) for bubbled cache contexts.

For most cases in core the #pre_render / #cache pattern is used, however there are use cases where that pattern is not enough, e.g.

1. Multiple Cache-Get / Prepare and render remainder

A number of rows can be prepared in fully, but only non-cached rows, should be prepared and rendered.

The #pre_render / #cache pattern is not enough here as they don't have any multiple support, but assume each row is rendered in a single way.

2. The internal page cache is not cache context aware and would need to implement #cache_redirect for cache context bubbling itself.

Proposed resolution

An ideal API would decouple the render caching implementation and allow to do:

<?php
$cached_rows
= $this->renderCache->getMultiple($render_cache_array_keyed_by_row_id);

// ...

foreach ($rendered_rows as $row_id => &$rendered_row) {
 
$this->renderCache->set($rendered_row);
}

return
$cached_rows + $rendered_rows;

A render_cache array is a render array with just the #cache, #attached and #markup property set.

Similarly page cache could work with render_cache_arrays for cacheGet / cacheSet.
?>

Remaining tasks

- Discuss
- Move cacheSet / cacheGet / createCacheId from Renderer service to RenderCache service.

User interface changes

- None

API changes

- Renderer::getCacheableRenderArray() would move the RenderCacheService::getCacheableRenderArray()


Viewing all articles
Browse latest Browse all 295807


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>