django-cacheops icon indicating copy to clipboard operation
django-cacheops copied to clipboard

Question about caching auth table and auth.user

Open kowsari opened this issue 4 years ago • 1 comments

I have seen in the various examples different settings for caching only get on auth.user table for 15 minutes. My question is why would you just want to cache the auth.user table for 15 minutes and only the get calls? Why not cache the auth user table just like other tables?

Any help is appreciated.

Thank you!

kowsari avatar Jan 25 '22 20:01 kowsari

Examples are examples. It might make sense though. E.g. cache miss is always slower than a non-cached call and adds load on Redis, so if you expect miss rate very high then you might bypass cache for such queries. Get queries tend to be simple, e.g. get by pk, while fetch may grow hairy, which means there are a lot of them:

select * from users where ...
select username from users where ...
select username, email from users where ...

select ... from users where date_joined > ...
select ... from users where is_staff

select ... from users where ... order by ...

Plus combinations of the above. Having many of them means the majority of them will be called rarely. Also a query touching more objects gets invalidated more often. Combined this means that many queries might be never hit, i.e. fetched from cache, because they are invalidated before they are repeated.

Automatic cache does not provide more granular separation than op, but sometimes it's enough. Especially if the most common use for a model is .get() queries, which is the case for auth.user.

Suor avatar Jan 27 '22 08:01 Suor