I'm building a site which will have multiple domain names pointing to it. The site will show different content depending on which domain the request is coming from. I have working access rights and query rewrites, but I am struggling with the drupal 8 cache system, and would appreciate some help getting forward.

I have implemented a custom cache context service which returns the host name from the request. I have added the cache context to all blocks via hook_block_build_alter and to all views via hook_views_pre_view. According to the cid in the cache_render table, this seems to be working. The context is added to the cache entries starting with entity_view:block and view:[view_name]:display.

However, drupal is still showing the cached content from site A when visiting site B. I can also see that even if duplicate cache entries are created, the saved content appears to be the same. What am I missing? And is there a way to add this cache context in a more global way?

Best regards,
Erlend

Comments

erlendsl’s picture

I have done some further testing, and my theory is that even though the rendered data from the views get the new cache context, the raw view results in the cache_data-table does not. How can I add cache contexts to these entries?