refs #1883 prevent opening multiple connections to the LDAP server
refs #1883 removed useless condition and duplicate code
refs #1883 corrected invalid usage on  inside inner loop
refs #1883 - Caching directly the rendered output