2

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?

0

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.

  • Note: hacking core is not advised. – Kevin Feb 7 '17 at 17:16
  • No, I did it on my owner module. – JohnTang Feb 9 '17 at 2:36

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.