Code example for LoadingCache

Methods: invalidateget

   protected void releaseAnyPublicIpForInstanceInRegion(String instanceId, String region) {
      if (!autoAllocateElasticIps)
      try { 
         String ip = elasticIpCache.get(new RegionAndName(region, instanceId));
         logger.debug(">> disassociating elastic IP %s", ip);
         client.getElasticIPAddressApi().get().disassociateAddressInRegion(region, ip);
         logger.trace("<< disassociated elastic IP %s", ip);
         elasticIpCache.invalidate(new RegionAndName(region, instanceId));
         logger.debug(">> releasing elastic IP %s", ip);
         client.getElasticIPAddressApi().get().releaseAddressInRegion(region, ip);
         logger.trace("<< released elastic IP %s", ip);
      } catch (CacheLoader.InvalidCacheLoadException e) {
         // no ip was found 
      } catch (ExecutionException e) {
         // don't propagate as we need to clean up the node regardless 
         logger.warn(e, "error cleaning up elastic ip for instance %s/%s", region, instanceId);