Disable the cache for a specific view I'm showing my users a random number ({{ random() }}) in a twig which is being rendered in a view. But when I refresh a page it just shows me the same number.

I tried several things but they all failed:


Disabled caching in admin/config/development/performance
Disabled cache in views advanced settings
tried to use cacheexclude module
I even disabled twig cache!


How can I completely disable cache for specefic twig or specefic view?

Update:

By the way in response header there is a header called x-drupal-cache:HIT. (It's MISS for the first time and then HIT after first load) Why?

Update 2:
I uninstalled Internal Page Cache too. the x-drupal-cache is gone now but the page is still being cached! I literally disabled everything but still no luck to show a random number in twig in a view..

This is my response header if it helps:

cache-control:must-revalidate, no-cache, private
content-encoding:gzip
content-type:text/html; charset=UTF-8
date:Wed, 28 Feb 2018 14:26:47 GMT
expires:Sun, 19 Nov 1978 05:00:00 GMT
server:nginx
status:200
strict-transport-security:max-age=15768000
vary:Accept-Encoding
x-content-type-options:nosniff
x-drupal-dynamic-cache:UNCACHEABLE
x-frame-options:SAMEORIGIN
x-generator:Drupal 8 (https://www.drupal.org)
x-ua-compatible:IE=edge


Solution:

I uninstalled Internal Cache module and ALSI big pipe module too.
Unfortunately point 1 doesn't work for anonymous traffic.

You have to uninstall the Internal Page Cache module.

Or trigger

\Drupal::service('page_cache_kill_switch')-&gt;trigger();


in a view hook.

When the View is placed on most or all pages then uninstall the Internal Page Cache, because the page cache kill switch also disables the dynamic page cache and you don't want to disable both caches, unless this is only for a few pages which don't have too much traffic.

Additionally you need point 2 (disabled cache in views advanced settings) in any case.

Update:


  By the way in response header there is a header called
  x-drupal-cache:HIT. (It's MISS for the first time and then HIT after
  first load) Why?


This header is generated by the Internal Page Cache, a HIT means it is served from this cache.