I have a custom entity that I've added some computed fields to, so the classes involved are:
class MyEntity extends ContentEntityBase
class ComputedFieldA extends FieldItemList
class ComputedFieldB extends FieldItemList
My issue is that I want the computed fields to either not be cached at all, or to be cached but with a different invalidation strategy.
Is what I want possible? Or do I just need to invalidate cache for the whole entity?
Edit: The custom field itself is basically a count of the rows in another database table. I want that count to be cached separately then invalidated if new rows are inserted.
The output is being consumed via the default jsonapi endpoint for the entity.
Edit 2: I guess this is more complex than I thought so I'll describe the entities in more detail:
Entity A:
- Has a 1:1 relationship with nodes based on UUID
- Has a count of Entity B entities that are related to the node (computed)
- Has a calculation based on that count (computed)
Entity B:
- Has an N:1 relationship with nodes based on NID
So, if a new Entity B is created for node X then I want the cache invalidated on the two computed fields of Entity A for node XXXX-XXXX-XXXX-XXXX so that the jsonapi endpoint shows up to date computed data.
If I can add a cache tag of node:X to each instance of the computed field I expect that would achieve what I want.