If you're reimplementing DNS lookups with caching in your own code, you are very likely doing something wrong.
The title of the entire story already had me confused, as it suggests you somehow need DNS for UDP. Everything that is presented here is a caching strategy.