Why do we develop lifelong immunity to some diseases, but not others?

Why do some diseases infect us again and again?