1

I have a few computed fields on my entity and they have dynamic values. These values cannot be cached because they change often.

I've created the necessary field formatter that uses the same approach that the comment module uses to display the uncached comment form by using the #post_cache_render callback.

This I found does not always work(the value is sometimes displayed in one view mode but not in another).

The other issue I have is that if the value is empty, the field label is still visible because it is not part of the formatter and therefore it is cached with the rest of the Entity View data.

So my question is: how can I use fields with dynamic values so they won't get cached in the Entity View?

I've also tried all hooks that allow adding or changing data in the Entity View but every single one get's cached and so I found it impossible to avoid the cache.

  • What type of dynamic values are we talking about? Written by Drupal PHP, updated externally directly via the database? – gogowitsch Jul 15 '18 at 8:06
0

You can not do it per field, that would defeat the purpose. The whole entity is cached.

You can disable render caching for your entity by setting render_cache = FALSE in your annotion and you can do it per view mode.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy