Fix some ugly bugs related to user login in cache module