Not sure if there is an official rule at certain schools...one of mine was about 3 or so years out from when I had him as a professor. Didn’t seem to bother anyone. Also, not sure if adcoms even look at specific date correlations with professors and their classes. I’d say that they still know you if you interacted a lot with them.
Good luck!