Lifelong Learning and Selective Forgetting via Contrastive Strategy