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

Add render_cache debug output

$
0
0

Problem/Motivation

Render Caching is great, but debugging asset / library adding and post_render cache can be really complicated, also it is difficult to see if there are cache hits or not.

In Drupal 7 render_cache module, I use twig style debug output, which works great.

Reference: https://github.com/LionsAd/render_cache/blob/770c615f6081e7d415dcae431ee...

Proposed resolution

Cache debug output

In drupal_render_cache_get() (soon in renderer service) add something like (pseudo-code):

  // _after_ get from cache
  if ($this->use_debug) {
     $elements = $this->addDebugOutput($elements, TRUE); // TRUE == Cache Hit
  }

  // _after_ set to cache
  if ($this->use_debug) {
     $elements = $this->addDebugOutput($elements, FALSE); // TRUE == Cache Miss
  }

  function addDebugOutput($elements, $cache_hit) {
        $prefix = '<!-- START RENDER (#pre_render): ' . print_r($elements['#pre_render'], TRUE) . "\n" . ' CACHE INFO: ' . "\n" . print_r($elements['#cache'], TRUE);
        $prefix .= "\nCACHE-HIT: " . $cache_hit ? 'YES' : 'NO' . "\n";
        $prefix .= "\nATTACHED: " . print_r($elements['#attached'], TRUE) . "\n";
        $prefix .= '-->';
        $suffix = '<!-- END RENDER: ' . print_r($elements['#pre_render'], TRUE) . ' -->';
        $elements['#markup'] = "\n$prefix\n" . $elements['#markup'] . "\n$suffix\n";
        return $elements;
  }

This is major, because it is almost impossible to debug render caching else. (I tried other ways ...)

The impact is minimal as when the option is turned off, there is no change in code.

Remaining tasks

- Make a patch!

User interface changes

- None

API changes

- New config option in services.yml to add render cache debug output.


Viewing all articles
Browse latest Browse all 295245

Trending Articles



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