If you have the metal for supports, mine around the tiles that are closest to the cave exit and build around them. Be careful with support placement though, it's annoying if you accidentally block a cornerpost's extension path with one that has already prevented a cave-in. This will make it easier to expand the walls if you want to do so in the future or build an airlock starting with normal gates at the cave exit instead of visitor if you wanted an escape method (ideally you would also have a locked house inside to drop aggro).
Otherwise, like Valgar said, just check which tiles are closest (unmine-able) by trying to mine them and ensure you are building your palisade walls in a way that no mine-able tiles can be reached from the cave exit side or which would allow for entry if mined such as diagonally.
I found a couple of examples from previous worlds. Visitor gates in front of the cave exit in the first image could instead be normal gates for an escape route if that is your preference. In the second image, red lines are the tiles that can't be mined. I would NOT recommend building your gate(s) as close as I have in my second image if you can avoid it, it's better to leave as much space as you can for stuff like horses, carts, leashed animals, etc.