How should one maintain a relationship with a professor?
If you don't plan to work with or take courses from this professor in the future, I advocate getting a letter of recommendation now instead of waiting. Services such as Interfolio allow your letter writers to upload a letter now that you can send out to any recipient at any time. This way, the professor still remembers you well; I can tell you from experience that after a couple of years of teaching large (>100 student) classes, even my better students start to fade together in my memory.