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

yoerioptr created an issue. See original summary.

yoerioptr’s picture

StatusFileSize
new534 bytes
kleiton_rodrigues’s picture

Status: Active » Needs review
StatusFileSize
new176.21 KB
new48.83 KB

@yoerioptr
I applied the patch and it looks good, with the removal of the code:
$ build ['# cache'] ['keys'] [0] = 'ds_entity_view';

swentel’s picture

Hmm interesting, will look at this at the end of the week!

swentel’s picture

Version: 8.x-4.x-dev » 8.x-3.x-dev

Moving branch for the test

yoerioptr’s picture

@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.

ds_entity_view:node:7262:full: 166 (languages:language_content, route, url, user.node_grants:view, user.roles:anonymous)
entity_view:node:7262:full: 166 (languages:language_content, route, url, user.node_grants:view, user.roles:anonymous)

After further investigation the stored data was exactly the same. Removing the line resulted in (almost) halving the consumed memory.

swentel’s picture

I 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.

swentel’s picture

There'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.

  • swentel committed 4e5689b on 8.x-3.x authored by yoerioptr
    Issue #3201340 by yoerioptr, kleiton_rodrigues: Duplicate cache entries
    

  • swentel committed 4d40dbf on 8.x-4.x authored by yoerioptr
    Issue #3201340 by yoerioptr, kleiton_rodrigues: Duplicate cache entries
    
swentel’s picture

Status: Needs review » Fixed

Committed and pushed, thanks.

Say hi to Bram ;)

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.