Sandeep
Sandeep

Reputation: 629

Redis in django-rest-framework in get method

I am using redis in django restframe work and geting problem in get method

I have save data for multiple users with different keys

@api_view(['GET'])
def abc(request):
    key  = request.META['HTTP_KEY']

    if  cache.get(key) == None:
        print('create a cache and return data ');
        cache.set(key,key,timeout =100)
        return JsonResponse({'data': cache.get(key) })
    else:
        print('return data from cache')
        return JsonResponse({'data': cache.get(key) })

first time it is creating a cache and return a data and when I hit next time with different key it will return same data event it is not execute the if else condition/not printing print command. I thing it create url base cache, how can solve this problem?

I hit with key "a" first time and it return me = a and print "create a cache and return data"

next time I hit with with key b, it return me old data "a" and not print any line 'create a cache and return data '/'return data from cache'

Upvotes: 1

Views: 845

Answers (1)

Jaskaran singh Rajal
Jaskaran singh Rajal

Reputation: 2330

Use this

from django.views.decorators.vary import vary_on_headers

@vary_on_headers('key')

'key' Please menstion your header key here

Using Very header

Upvotes: 1

Related Questions