I plan to cache some of my endpoints powered by DRF, and I want to update the cache wherever it is appropriate. So basically I need to somehow understand what key corresponds to the given cache. As far as I understand, Django does not provide such an opprotunity, right ? Before inventing a bicycle, I would like to make sure that there's no inbuilt feature for it.
For example, I have the following code:
from django.views.decorators.cache import cache_page from rest_framework.views import APIView from rest_framework.response import Response
class CachedAPIView(APIView): @cache_page(60 * 15) # Cache for 15 minutes def get(self, request): # Your view logic here data = {'message': 'This is a cached response!'} return Response(data)
def post(self, request):
# Here I want to somehow locate my key based on query details and update its value