def update_cache_when_comparison_target_updated(sender, instance, created, **kwargs): """ Update cache when comparision target updated """ redis.set_comparison_target_list_cache(instance.survey) if created == False and instance.user in instance.survey.participants.all(): redis.set_survey_data_of_comparison_targets_cache(instance.survey)
def list(self, request, *args, **kwargs): """ List all comparison targets in specific survey """ try: survey = Survey.objects.get(id=int(request.GET["survey_id"])) except: return Response(status=status.HTTP_400_BAD_REQUEST) comparison_targets = cache.get("survey:" + str(survey.id) + ":comparison_targets:list") if comparison_targets is not None: return Response(comparison_targets) else: comparison_targets = redis.set_comparison_target_list_cache(survey) return Response(comparison_targets)