Use connection cache (one per host, up to 16 hosts). Rename some parameters to avoid shadowing a global variable.