I am using serializer to get the related data for a particular resource like this:
SessionSerializer.py
def to_representation(self, instance):
response = super().to_representation(instance)
response["user"] = UserSerializer(instance.user).data
if instance.experiment:
response["experiment"] = ExperimentSerializer(instance.experiment).data
response["last_event"] = EventSerializer(instance.last_global_event).data
# fetch and return all session answers tied to this session
response["session_answers"] = instance.sessionanswer_set.values()
return response
I am also using DRF cache decorators in the SessionViewSet, which seems to be working fine. However, I cannot invalidate the cache data when there is an update to the instance and/or if there is an update to any related instance (like user).
Is there a standard practice or documentation for how to clear cache data when there is an update?