Problem/Motivation
For some reason DS seems create duplicate cache entries that have already been set by Drupal.
Steps to reproduce
- Setup a Drupal 8.x site
- Install and configure Display Suite
- Enable caching (database / redis / ...)
Proposed resolution
in the hook 'template_preprocess_ds_entity_view' DS tries to alter the list of cache keys. This change seems to create duplicate cache entries. A quick fix (in my case) is removing the code snippet as shown below.
$configuration = $build['#ds_configuration'];
// Process the render array so we can reuse it.
// Don't add/override the cache key if there aren't any.
if (!empty($build['#cache']['keys'])) {
$build['#cache']['keys'][0] = 'ds_entity_view';
}
unset($build['#theme']);
$configuration = $build['#ds_configuration'];
unset($build['#theme']);
unset($build['#pre_render']);
Comments
Comment #2
yoerioptr commentedComment #3
kleiton_rodrigues commented@yoerioptr
I applied the patch and it looks good, with the removal of the code:
$ build ['# cache'] ['keys'] [0] = 'ds_entity_view';Comment #4
swentel commentedHmm interesting, will look at this at the end of the week!
Comment #5
swentel commentedMoving branch for the test
Comment #6
yoerioptr commented@swentel, Maybe this will help you in any way.
While debugging an application for memory leaks (in our case Redis that immediately got flooded with data), the duplicate cache entries seemed to be (part of) the issue. One of which was a caused by Display Suite. For example.
After further investigation the stored data was exactly the same. Removing the line resulted in (almost) halving the consumed memory.
Comment #7
swentel commentedI can confirm the double entries. The difference, at least here, is in the #attached key which contains more for the the original entity_view, the content seems to be same. (a quick scan seems to be the html_head_link key in the original, which is missing in the ds cache entry)
Digging further, I'm so confused what's happening here.
Comment #8
swentel commentedThere's a key missing. You normally have two entries: one with the markup, and one with more metadata. The ds_entity_view only exists once, so this is a bad thing anyway as it's impossible then for the render cache to get it from cache again. So it's an obsolete entry.
I've contacted my other maintainer to have a look at this line too. It's very old, so chance is small that we will remember too why it was added :) However, my gut feeling also says that it probably can be deleted anyway.
Comment #11
swentel commentedCommitted and pushed, thanks.
Say hi to Bram ;)