-
Notifications
You must be signed in to change notification settings - Fork 230
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow multiple keys for cache_on_save #212
Comments
Are you willing to make a pull request? |
I have not made the pull request because I don't know if other find there is a need for this feature or if the solution is correct. I have noticed for instance that having two keys, stores the same object two times in Redis
point to two objects that contains the same data, they should point to the same result?
|
Key is determined by queryset, there is no way to know that 2 different querysets result in same thing until you execute them. So, yes, same object is stored twice under 2 different keys. This is normal behavior and your implementation is correct regarding this issue. You should, however, handle The idea of somehow compressing it, e.g. using content addressed values in cache with queryset keys refering to single stored object is interesting, but probably won't be worth the hustle. |
P.S. You can probably rewrite every place you use username to use id and thus solve this for your case. Do you really need 2 unique fields in a model? |
I really only need to cache by (I don't find clean to make |
You can just disconnect pre_save signal as a quick fix.
|
I use django-cacheops for managing MySQL replication lag, so I set cache_on_save to avoid fast reads after write to get stale data, I think it will be handy to be able to specify multiple keys.
An example:
I usually get User model by
id
or byusername
so both queries are cached pointing to the same object:If I set cache_on_save to one of them for instance
username
, when User is modified the other cache is deleted so nextUser.objects.get(id=108547)
will hit the database.My suggested implementation:
The text was updated successfully, but these errors were encountered: