Suggestion for an additional flagging cache tag

Created on 28 July 2025, 8 days ago

Problem/Motivation

If I render a component differently depending on whether or not a user has a flagging to a certain entity, it can be complicated to know when to invalidate the render cache.

Cache tags would normally be the way to handle this, but the module only provides the default cachetags from core with the flagging entity's ID, which is not available when the flagging doesn't exist (i.e. the user does not follow an entity, so the component is rendered one way, but once the user starts following this entity, the component needs to be re-rendered. There's no flagging entity ID to add a cachetag for the first render).

Steps to reproduce

N/A

Proposed resolution

We can introduce a new cachetag that's invalidated whenever a flagging on all CRUD operations, in the form:
flagging:[flagging-type]:[host-entity-type]:[host-entity-id]:[user-id]

More variations can be added if needed. Maybe:

flagging:[flagging-type]:[host-entity-type]:[host-entity-id]
flagging:[flagging-type]:[host-entity-type]:*:[user-id]

This can be useful when building a stat of all flaggings on a single entity or by a single user.

Remaining tasks

Implement getCacheTagsToInvalidate() in Flagging.php

User interface changes

N/A

API changes

N/A

Data model changes

N/A

Feature request
Status

Active

Version

4.0

Component

Flag core

Created by

🇬🇧United Kingdom khaled.zaidan

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024