Casters always perform the following actions in succession:
Using a fast weapon which attacks continuously while holding the attack button makes for an effective shield against Casters' projectiles. Weapons like the Muramasa will work perfectly (even Pickaxes, Hammers, or Axes will work reasonably well, as their swings similarly don't require individual clicks).
The Death Sickle , Mushroom Spear , Chlorophyte Saber , Vilethorn or the Nettle Burst are effective both for taking down projectiles and attacking Casters, since they are the only weapons available to the player that can travel through walls. They have the best chance of stopping projectiles early, being capable of taking down projectiles at a reasonable distance even when they are coming through a thick wall. They are also good for attacking Casters when they are out of reach due to teleporting behind walls.
After Casters have fired their 3-projectile volley, there is a 3-second gap until they teleport; this is the perfect time to attack. Once you have started attacking, make sure you don't stop for too long, or else they will teleport again. Repeated attacks prevent Casters from firing or teleporting away.
Sometimes it is best to shield off their attacks when they are far away or in a hard-to-reach area, and wait until they teleport within attack range.