The long-term immunity that follows an initial immune response to a pathogen, including primary and secondary responses.