(Sorry, looks like I wrote more than planned. Short version: Be a confident human and the vast majority of dogs won't hurt you.)
Had to deal with dogs while cycling too many times in many places (Spain, Italy, Egypt, E. Africa, western USA), and used to be married to a dog trainer. So here's my amateur working theory, for what it's worth...
I believe dogs (like people) that mean you serious harm are very rare. Doesn't mean they won't try to hurt you, just that they're not trying to kill you. For most dogs a human on a bike is sport. There's also a territorial component, but that's not why they chase people on bikes. A person on a bike, to a dog, is about the size of and moves at the speed of the kind of game it might have evolved or been bred to chase in the wild - a deer, say. Most dogs have a deeply conditioned urge to chase game, especially in packs. What most dogs don't do (unless trained to) is attack people. They know that's trouble.
So the best thing to do when chased by threatening dogs is to stop and get off the bike (but keep the bike between you and them if possible). All of a sudden, to a dog, you've then become a human, not game. Even better, appear as big and threatening and noisy as possible and look like you're about to attack them. The vast majority of the time that's enough to make them understand you're trouble and they'll back off. If they still hang around, walk away, keeping them in sight, until they lose interest, which will be at the edge of their territory, which is not usually all that large, especially if there's neighbours.
Many suggest that dogs are protecting their territory, because they appear to stop chasing abruptly at some seemingly arbitrary boundary. It might be a factor, but I think they stop there not because you've left their territory, but because they've reached the edge. Beyond there the dog feels less safe and the game is no longer fun. Most domestic dogs of the kind that might come running out at you from the yard of a house are just very bored.
Learning a little doggy body language is helpful. In most cases, as soon as a dog realises you're a confidently behaving human, they'll switch from chase to submissive behaviour. The tail will lift, they'll be trying to sniff or lick, and get close for some petting. If a dog stops when you stop, keeps a distance, stays still, tense and staring, tail down, then it's sizing up whether you're worth the fight. Again, be big and confident, walk away, but cautiously. In the worst case, be prepared to do some damage. It's a very rare dog (likely trained) that will keep coming at you after a well-placed bash (go for the nose) from a frame pump.
In all cases trying to outrun is only for when you're sure they're just playing and you want the workout. You'll never outrun anything but the smallest dog that really means business and on the bike you can't defend or attack. Audible and spray devices aren't all that useful because you can never be sure if they're going to work (they often don't, in my experience).