Code example for Cache

Methods: getIfPresentputsize

  public synchronized static MongoClient getClient( 
      List<ServerAddress> addresses, MongoClientOptions clientOptions)
      throws UnknownHostException {
    // Take the first replica from the replicated servers 
    ServerAddress serverAddress = addresses.get(0);
    MongoClient client = addressClientMap.getIfPresent(serverAddress);
    if (client == null) {
      client = new MongoClient(addresses, clientOptions);
      addressClientMap.put(serverAddress, client);
      logger.debug("Created connection to {}.", serverAddress.toString());
      logger.debug("Number of connections opened are {}.", 
    return client;