How to Invalidate cache for views by user's location My site using Drupal 8 last version (8.2.5) and we have the views which contains the filter based on user's location (time-zone). For example, the users are coming from UK will get the time in UK timezone, and the Users are coming from the US, will get the time in the US. The problem is, when anonymous users from UK accessing to the site, it's display as US time instead, because the page has cached from US when the users from US visited.

On Drupal 7, I had implements DrupalCacheInterface and set custom cache for APC. And it's working fine.

How can I customize Drupal 8 cache for this requirement? My web server enabled the opcache and I and a custom module already.

Updated:


After reference from Cache API from drupal.org, I tried to use Cache Context for TimeZone.


Inside default.services.yml, I modified:

# @default ['session', 'user']
  contexts: ['timezone']
  # Tags with a high invalidation frequency.


For make it filter by context request, when detect difference timezone will render cached pages according. But seems it's not working on Anonymous page cache.

Anyways for resolve my issue?
I resolved it by copy the Core Page Cache Module to my owner module, then disable Page Cache Module.

getCacheId(Request $request)


this function should be return a custom key is reach my goal.