Almacenamiento en caché de conexiones

Cuando se realiza una conexión a un servidor, el identificador de conexión se almacena en caché en el equipo cliente para ese proceso hasta que se cierra esa conexión. Si se usan el mismo servidor, puerto y credenciales en una conexión posterior, y solo las marcas de autenticación ADS_FAST_BIND o ADS_SERVER_BIND difieren, ADSI reutilizará la conexión existente. ADSI realiza el almacenamiento en caché de esta conexión por proceso.

Para aumentar el rendimiento, reutilice las conexiones existentes siempre que sea posible.

A continuación se muestra un ejemplo de uso de IAD en Visual Basic (consulte también Uso de las interfaces de IAD):

Dim cachedConn As IADs
Dim obj As IADs
Dim cachedName As String
Dim objName As String
 
' Connect to the server and maintain this handle to cache the connection.
Set cachedConn = GetObject("LDAP://MyMachine/DC=MyDomain,DC=Fabrikam,DC=com")
 
cachedName = cachedConn.Get("distinguishedName")
Debug.Print (cachedName)
 
' Reuse the connection to MyMachine opened by cachedConn.
' Be aware that this line executes quickly because it is not required
' to transmit over the network again.
Set obj = GetObject("LDAP://MyMachine/CN=Bob,CN=Users,DC=MyDomain,DC=Fabrikam,DC=com")
 
objName = obj.Get("distinguishedName")
Debug.Print (objName)
 
' Release the second connection.
Set obj = Nothing
 
' Reuse the connection to MyMachine opened by cachedConn again.
Set obj = GetObject("LDAP://MyMachine/CN=Administrator,CN=Users,DC=MyDomain,DC=Fabrikam,DC=com")
 
objName = obj.Get("distinguishedName")
Debug.Print (objName)
 
' Release the second connection again.
Set obj = Nothing
 
' Release the first connection.
Set cachedConn = Nothing
 
' The connection to MyMachine is closed.

En el ejemplo alternativo siguiente se muestra cómo funciona el almacenamiento en caché de conexiones mediante el objeto DirectoryEntry en .NET:

// Connect to the server and maintain this handle to cache the connection.
using (DirectoryEntry? cachedConn = new DirectoryEntry("LDAP://MyMachine/DC=MyDomain,DC=Fabrikam,DC=com")) 
{
    DirectoryEntry? secondConn;
    string? cachedName;
    string? objName;

    cachedName = cachedConn.Properties["distinguishedName"].Value?.ToString();
    Debug.WriteLine(cachedName);

    // Reuse the connection to MyMachine opened by cachedConn.
    // Be aware that this line executes quickly because it is not required
    // to transmit over the network again.
    using (secondConn = new DirectoryEntry("LDAP://MyMachine/CN=Bob,CN=Users,DC=MyDomain,DC=Fabrikam,DC=com"))
    {
        objName = secondConn.Properties["distinguishedName"].Value?.ToString();
        Debug.WriteLine(objName);

        // Release the second connection.
        secondConn = null;

        // Reuse the connection to MyMachine opened by cachedConn again.
        secondConn = new DirectoryEntry("LDAP://MyMachine/CN=Administrator,CN=Users,DC=MyDomain,DC=Fabrikam,DC=com");

        objName = secondConn.Properties["distinguishedName"].Value?.ToString();
        Debug.WriteLine(objName);
    }
    // Release and dispose the second connection
}
// The connection to MyMachine is closed and disposed

Consulte también

DirectoryEntry

Uso de interfaces de IAD