0

I'm caching a piece of render array by adding cache keys to it. It's getting cached correctly, but I see two rows for every instance of it.

One looks normal -- contains the render array, with a cid that looks like:

CACHE_KEY:[languages:language_interface]=en:[languages:language_url]=en:[theme]=MYTHEME:[user.permissions]=HASH

The other one had data that starts like:

a:2:{s:15:"#cache_redirect";b:1;s:6:"#cache";a:5:{s:4:"keys";a:1 ...

and its CID is:

CACHE_KEY:[languages:language_interface]=en:[theme]=MYTHEME:[user.permissions]=HASH

It looks like this is something to do with language negotiation, but why, and is this normal? The page I am loading when I am testing this is using the language prefix, so I'm not getting redirected.

1
  • 2
    What do you mean you are not getting redirected? The cache redirect has nothing to do with a redirect you might experience when using language prefixes and a route normalizer. The cache redirect is for cache items which bubble up cache contexts while rendered. So this depends on the content of your render array, not on language negotiations. The second CID contains only the three default contexts which are pre-configured and so they are always present even if you only specify cache keys without any cache contexts.
    – 4k4
    Jun 3 '20 at 16:23
0

It's still a bit unclear what you are asking, but to be more precise about my comment. The bubbled up cache contexts depend initially on the content of the render array, but this content can be dependend on other things. For example a rendered link can depend on a configured language negiotiator which provides a path processors rendering links differently dependend on the language and so bubbles up the cache context you have identified.

2
  • What I'm asking is 'Why is my cache table filling up with what appear to be weird sort-of duplicate rows, and have I done something wrong to cause this to happen?'
    – joachim
    Jun 4 '20 at 9:30
  • 1
    No, nothing is wrong. This happens if cache contexts are added by rendering the content of the render array. In your case the render array might contain a link which is rendered differently for each language prefix. Then Drupal needs to vary the cache by this additional cache context while at the same time mainain a cache entry for the original CID to be able to find it.
    – 4k4
    Jun 4 '20 at 9:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.