The adaptive immune system in vertebrates consists of highly diverse immune receptors to mount specific responses against a multitude of pathogens. A central feature of the adaptive immune system is the ability to form a memory to act more efficiently in future encounters with similar pathogens. However, memory formation especially in B-cells is one of the least understood cell fate decisions in the immune system. Here, we present a framework to characterize optimal strategies to store memory in order to maximize the utility of immune response to counter evolving pathogens throughout an organism’s lifetime. To do so, we have incorporated the kinetics and energetics of memory response as ingredients of non-equilibrium decision-making between an adaptive exploration to mount a specific and novel response or exploitation of existing memory that can be activated rapidly yet with a reduced specificity against evolved pathogens. To achieve a long-term benefit for the host, we show that memory generation should be actively regulated and dependent on immune receptors’ affinity, with a preference for cross-reactive receptors with a moderate affinity against pathogens as opposed to high affinity receptors— a recipe that is consistent with recent experimental findings [1, 2]. Moreover, we show that the specificity of memory should depend on the organism’s lifespan, and shorter-lived organisms with fewer pathogenic encounters throughout their lifetime should store more cross-reactive memory. Overall, our framework provides a baseline to gauge the efficacy of immune memory formation in light of an organism’s coevolutionary history with pathogens.