It happens to me everyday. I work with a variety of military classes and spend days with the students. I can be in the grocery store or the movies or whatever and I hear "Mrs. Tina, Mrs. Tina or I hear Mrs. xxxxx"
I usually just smile and make normal small chitchat with them. I don't typically ask their name unless I was going to be working/seeing them on a regular basis.
You can politely say something like "My brain is still on summer vacation, what is your name again?" If someone just say hello and starts to chitchat but doesn't call you by name, say something like I'm so bad with names, I'm *insert your name* and that person will also say their name. After he/she tells you the name, repeat it back saying something like "Nice to see you again, Mary/Joe/Jane/Jim."