Timeline for Invalidate Internal Page Cache at certain times in a day for anonymous users
Current License: CC BY-SA 4.0
13 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Aug 6, 2019 at 12:49 | comment | added | Hudri |
I've tried similar solutions, and finally switched over to adding custom cache tags, and invalidating those cache tags by cron. E.g. I added a $variables['#cache']['tags'][] = 'MIDNIGHT'; in preprocess and invalidated it with a corresponding \Drupal\Core\Cache\Cache::invalidateTags(array('MIDNIGHT')); in the hook_cron of the same module
|
|
Aug 6, 2019 at 10:39 | history | edited | Baud | CC BY-SA 4.0 |
added 631 characters in body
|
Aug 6, 2019 at 9:21 | answer | added | 4uk4 | timeline score: 1 | |
Aug 6, 2019 at 9:11 | comment | added | 4uk4 | But the internal page cache for anonymous users gets the result from the dynamic cache and you need to make sure this delivers the correct result by adding the cache context. BTW invalidating is the wrong term here, you vary the cache id by a context and you have to do this in two places because one of the caches doesn't understand the standard Drupal way to do this (and wouldn't be able to run most contexts, because it is too early in the bootstrap process). | |
Aug 6, 2019 at 9:04 | comment | added | Baud | @4k4 I get it: Contexts are for dynamic caching. I would like to focus my question only for anonymous user and internal page cache: how to invalidate this page cache when the store is closed or opened? | |
Aug 6, 2019 at 9:01 | history | edited | Baud | CC BY-SA 4.0 |
deleted 62 characters in body
|
Aug 6, 2019 at 8:22 | comment | added | 4uk4 | Yes, a custom cache context with exactly the same logic. You need the cache context for all other caches in Drupal like the entity render cache and the dynamic page cache and if you add the context to the node it will bubble up to all cache levels. With one exception, the Internal Page Cache, for which you are trying to find a solution in getCacheId(). | |
Aug 6, 2019 at 7:54 | comment | added | Baud |
@4k4 I have 2 issues regarding creating a context: 1-I will have to implement get_context() with exactly the same logic as in getCacheId() (see upper)=>looks weird 2-My idea is to keep the internal page cache module, I have read somewhere else that it doesn't deal with context. Thank you for the route not being present, I will update the code
|
|
Aug 6, 2019 at 7:46 | comment | added | Baud | @leymannx: it is about invalidating the whole cache page | |
Aug 6, 2019 at 6:40 | comment | added | 4uk4 | The cache context doesn't exist, you have to create a custom one and add it to the node, a preprocess hook is OK for this. BTW you can't rely on the route name being present in the middleware, it's only there when storing the cache item but not when retrieving it. So better use the path to check the node type. | |
Aug 6, 2019 at 5:10 | review | Close votes | |||
Aug 21, 2019 at 3:05 | |||||
Aug 6, 2019 at 4:53 | comment | added | leymannx | Is this really about invalidating the whole page cache or is it more about displaying a certain message at certain times? | |
Aug 5, 2019 at 22:17 | history | asked | Baud | CC BY-SA 4.0 |