I'm noticed on a clean Drupal installation, the cache context url.query_args is present on ALL requests, that cause one entry on cache_render table per each request (if we change some query params, think about analitycs queries), and that table grows extremely fast. I don't know if this is necessary for ALL pages. Can I disable this behaviour from a config? Is this neccesary for Drupal to work properly?
1 Answer
No, in a clean Drupal installation this should not happen. These are the default cache contexts set in core.services.yml:
parameters:
renderer.config:
required_cache_contexts: ['languages:language_interface', 'theme', 'user.permissions']
What you might have found are cache entries from the Internal Page Cache for anonymous requests, which doesn't use cache contexts. Instead it stores the cache entries with the complete URL including the query string as cid. There are a lot of complaints that the Internal Page Cache fills up the database even for sites with moderate traffic. Not only because of the variations by the query string, also because the entries have no expire date and there is no way to configure one in UI. But you can easily replace the Internal Page Cache with Varnish or a CDN. You only have to configure the third party solution to invalidate the Drupal cache tags. Another option is to replace the cache backend with a solution that provides an automatic expiration like Memcache or Redis.
-
Is there an open issue on drupal.org for the query-params/internal-page-cache problem?– znerolCommented Jun 24, 2017 at 12:49
-
-
I made some test after your response. I disabled both modules, Internal Page Cache (page_cache) and Internal Dynamic Page Cache (dynamic_page_cache) but the cache_render table is still growing on each request. I activated the http.response.debug_cacheability_headers: true to see the cache contexts and I always see the url.query_args on the http headers, not sure if is related to this.– GerardoCommented Jun 26, 2017 at 13:54
-
This context is not in all pages in a clean Drupal installation. Do the pages contain a view with a pager? In this case this context is needed obviously and is added by the pager. But there may be other code that adds the context. You can look in cache_render which cached elements have the cache context added to the cid. This should point in the direction.– 4uk4Commented Jun 26, 2017 at 14:19