あなたは代わりにあなたDBのmemcachedのヒットcustom authentication classを作成することができます。
class ExampleAuthentication(authentication.BaseAuthentication):
def authenticate(self, request):
token = request... # get your token here
if not token:
return None
try:
# user = User.objects.get(username=username) -> This is the original code from the link above
user = ... # get your user based in token here
except User.DoesNotExist: # some possible error
raise exceptions.AuthenticationFailed('No such user')
return (user, None)
その後、すなわち、ビューごとに独自の認証クラスを使用することができます。
class ExampleApiView(APIView):
authentication_classes = (CustomTokenAuthentication,)
def get(self, request, *args, **kwargs):
...