diff --git a/zephyr/lib/cache.py b/zephyr/lib/cache.py index 7f06bc376d..c80dce7e6e 100644 --- a/zephyr/lib/cache.py +++ b/zephyr/lib/cache.py @@ -72,3 +72,12 @@ def update_user_profile_cache(sender, **kwargs): items_for_memcached[userprofile_by_email_cache_key(user_profile.user.email)] = (user_profile,) items_for_memcached[userprofile_by_user_cache_key(user_profile.user.id)] = (user_profile,) djcache.set_many(items_for_memcached) + +# Called by models.py to flush the user_profile cache whenever we save +# a user_profile object +def update_user_cache(sender, **kwargs): + user = kwargs['instance'] + items_for_memcached = {} + items_for_memcached[user_by_id_cache_key(user.id)] = (user,) + djcache.set_many(items_for_memcached) + diff --git a/zephyr/models.py b/zephyr/models.py index 8290c333b5..daf116a879 100644 --- a/zephyr/models.py +++ b/zephyr/models.py @@ -2,7 +2,8 @@ from django.db import models from django.conf import settings from django.contrib.auth.models import User import hashlib -from zephyr.lib.cache import cache_with_key, update_user_profile_cache +from zephyr.lib.cache import cache_with_key, update_user_profile_cache, \ + update_user_cache from zephyr.lib.initial_password import initial_api_key import os from django.db import transaction, IntegrityError @@ -81,6 +82,8 @@ class UserProfile(models.Model): # Make sure we flush the UserProfile object from our memcached # whenever we save it. post_save.connect(update_user_profile_cache, sender=UserProfile) +# And the same for the User object +post_save.connect(update_user_cache, sender=User) class PreregistrationUser(models.Model): email = models.EmailField()