2

I am using TokenAuthentication for several of my DRF views. The view code itself have optimized logic for to use memcached if the key exists in the cache - to speed up by reducing DB queries. However, I see that for each of the API requests from phone(client), the server still does one query at least - Postgres authtoken_token select for validating user for the authtoken sent

Is there a way to avoid this, since the authtoken is rarely changed - by keeping it in the cache?

I am using the following in settings.py, but I don't think this is helping my case

SESSION_ENGINE = "django.contrib.sessions.backends.cached_db"
dowjones123
  • 3,695
  • 5
  • 40
  • 83
  • Cannot find any code utilizing cache for token auth in DRF 3.3.1. Simply a model filter query for every request... – Cloudream Dec 01 '15 at 13:21

1 Answers1

0
  • You can set TIMEOUT to None while setting token in memcache, such that cached token will never expire (untill memcache server restart/eviction). Or you can set long duration for timeout to minimize the DB queries.
  • Alternatively you can opt for Redis with django-redis as you caching backend. Redis provides persistant cache option.
Rajesh Kaushik
  • 1,471
  • 1
  • 11
  • 16