I discovered this quite by accident after having to unclog the nozzle on a can of hairspray for the gazillionth time.
After using a can of hairspray—assuming it is not clogged and sprays well—run water over the nozzle area. No need to rub or wipe it. Dump off any excess water, but DO NOT dry.
Do the same to the inside of the lid. Both the top of the can with the spray nozzle and the inside of the cap should have droplets remaining on the surfaces.
Replace the cap tightly. (If the cap has a little hole in the top, cover it with tape before doing this.). That’s it.
I have gone weeks between sprays and have not had a clogged sprayer for years. The water does not affect the hairspray at all, it just keeps a high moisture level in the cap so the spray in the nozzle can’t dry out.