-
Notifications
You must be signed in to change notification settings - Fork 158
Make it easy to invalidate auth.User (and other 3rd-party models) #1
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
Comments
Sorry, I meant to say that when User.objects.filter(username="test").update(username="something else") gets called, then Profile.objects.filter(user__username="test") will return a stale object. Although you could say the same thing for Profile.objects.filter(some_field="test").update(some_field="something else") |
|
Ok, might be good to update the documentation to make it explicit that you need to switch out the manager for models related to the object that's getting cached as well, or manually add those signals. |
I've managed to enable auth.user like this: User.__bases__ = (caching.base.CachingMixin, models.Model)
UserManager.__bases__ = (caching.base.CachingManager, models.Manager) Unfortunately I experience strange effects on creating new User instances. Anonyone actually did manage to cache auth.user properly? |
@turingmachine I think you need to manually call https://github.com/jbalogh/django-cache-machine/blob/9b34f/caching/base.py#L37 |
@turingmachine @jbalogh Did you figure it out already how to cache auth.User properly already? |
Eventually the solution was to maintain an own fork of django, with caching changes applied to auth.User. |
I'd love to see a solution that one can use to extend a normal Django installation, since we prefer to use the Django packages from Debian! Does anyone have an example of code that extends Auth to include caching? |
@timstoop it happens that I've been wrangling with this myself. I've got the following solution in my dev environment now. There might be a hidden gotcha I've missed but it appeara to be working so far. Apply this as a monkeypatch after
(I should also point out that this has been applied against a Django 1.4 installation... it's possible the new User model might need a slightly different approach but I haven't looked at it yet.) |
That actually works very good! Thanks! |
Was able to use a similar approach to solution provided by @tgross for Django 1.5 since the user models have been changed, and are handled differently.
|
Maybe this project can help: https://github.com/ui/django-cached_authentication_middleware |
try to simplify Django 1.8/Django 1.11 compatibility
This looks interesting and is very similar to what I've been working on. I could be missing something, but from what I can tell queries on related tables won't get invalidated. For example:
profile = Profile.objects.filter(user__username="test")
should get invalidated when either profile or user are saved/deleted, but I think this would only invalidate when profile is saved/deleted.
Also, the post_save and post_delete signals won't get fired on queryset.update, so if I were to do something like Profile.objects.filter(user__username="test").update(username="something else")
then Profile.objects.filter(user__username="test") will return a stale object. You could override the queryset's update method, but you'd still have the same problem as above with related models.
The text was updated successfully, but these errors were encountered: