@receiver(models.signals.post_save, sender=UserProfile)
def invalidate_user_profile_country_cache(sender, instance, **kwargs):
 changed_fields = getattr(instance, '_changed_fields', {})
 if ('country' in changed_fields):
  cache_key = UserProfile.country_cache_key_name(instance.user_id)
  cache.delete(cache_key)
  log.info('Country changed in UserProfile for %s, cache deleted', instance.user_id)

@ receiver ( models . signals . post_save , sender = UserProfile ) def invalidate_user_profile_country_cache ( sender , instance , ** kwargs ) : changed_fields = getattr ( instance , '_changed_fields' , { } ) if ( 'country' in changed_fields ) : cache_key = UserProfile . country_cache_key_name ( instance . user_id ) cache . delete ( cache_key ) log . info ( 'Country changed in UserProfile for %s, cache deleted' , instance . user_id )
invalidate the cache of country in userprofile model .