我在django restframe工作中使用redis,在get方法中使用get问题
我已使用不同的密钥为多个用户保存数据
@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) })
第一次创建缓存并返回数据时,当我下次使用不同的键单击时,它将返回相同的数据事件,它不会执行if-else条件/不打印打印命令。我认为它可以创建url基缓存,如何解决这个问题?
我第一次按“a”键,它返回我=a并打印“创建缓存并返回数据”
下次我按b键时,它会返回旧数据“a”,并且不会打印任何行“创建缓存并返回数据”/“从缓存返回数据”