def get(_, lang, topic_id): if lang == 'ja': cached_topic = Cache.get('api_topic_' + str(topic_id)) if cached_topic is None: topic = Topic.get_topic_published_by_id(topic_id) if topic is None: return JsonResponse({ 'message': 'Not Found' }, status=404) res = TopicSerializer(topic).data Cache.set('api_topic_' + str(topic_id), res) else: res = cached_topic elif lang == 'en': cached_topic_en = Cache.get('api_topic_en_' + str(topic_id)) if cached_topic_en is None: topic = TopicEn.get_topic_published_by_id(topic_id) if topic is None: return JsonResponse({ 'message': 'Not Found' }, status=404) res = TopicEnSerializer(topic).data Cache.set('api_topic_en_' + str(topic_id), res) else: res = cached_topic_en else: return JsonResponse({ 'message': 'Not Found' }, status=404) return JsonResponse(res, safe=False)