The key is to want to learn it and know it for the rest of your life, not for the sake of doing well on the course or any other relatively short term goal. Like, imagine that you want to tell your grandkids about this, dunno if that example works but it should be that kind of mindset. I have a fair memory of almost everything, not perfect but fair. I can remember the outlines of any lecture in a subject I don't care about and haven't used ever since, not even on a test or so, a year after it went.
But by summoning my will to want to learn something I can push in a great deal of detail as well in the memory and it still stays indefinitely.
By the way, how rare are people who have really good memories? When I was younger I thought that everyone had a memory like me but the more I talk to people the more I notice that people in general forget just about everything they experience. Aside from family members I have just met two with exceptional memories like that, one which is a maths professor.