Guava LoadingCache - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Guava LoadingCache class.

This code example shows how to use the following methods:put, getUnchecked
         return null; 
      String containerName = from.getContainer();
      if (containerName == null)
         return null; 
      try { 
         URI uri = cdnContainer.getUnchecked(containerName);
         if (uri == NEGATIVE_ENTRY) {  // intentionally use reference equality
            // TODO: GetCDNMetadata.load returns null on failure cases.  We use 
            // a negative entry to avoid repeatedly issuing failed CDN queries. 
            // The LoadingCache removes this value after its normal expiry. 
            return null; 
         } 
         return uriBuilder(uri).clearQuery().appendPath(from.getName()).build();
      } catch (CacheLoader.InvalidCacheLoadException e) {
         // nulls not permitted from cache loader 
         cdnContainer.put(containerName, NEGATIVE_ENTRY);
         return null; 
      } catch (NullPointerException e) {
         // nulls not permitted from cache loader 
         // TODO this shouldn't occur when the above exception is reliably presented 
         return null; 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:put, getUnchecked
         return null; 
      String containerName = from.getContainer();
      if (containerName == null)
         return null; 
      try { 
         URI uri = cdnContainer.getUnchecked(containerName);
         if (uri == NEGATIVE_ENTRY) {  // intentionally use reference equality
            // TODO: GetCDNMetadata.load returns null on failure cases.  We use 
            // a negative entry to avoid repeatedly issuing failed CDN queries. 
            // The LoadingCache removes this value after its normal expiry. 
            return null; 
         } 
         return uriBuilder(uri).clearQuery().appendPath(from.getName()).build();
      } catch (CacheLoader.InvalidCacheLoadException e) {
         // nulls not permitted from cache loader 
         cdnContainer.put(containerName, NEGATIVE_ENTRY);
         return null; 
      } catch (NullPointerException e) {
         // nulls not permitted from cache loader 
         return null; 
      } 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:invalidate, get
 
   protected void releaseAnyPublicIpForInstanceInRegion(String instanceId, String region) {
      if (!autoAllocateElasticIps)
         return; 
      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 
         return; 
      } 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);
      } 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:put
   } 
 
   @Override 
   public URI apply(String input) {
      URI uri = sync.enableCDN(input);
      cdnContainer.put(input, uri);
      return uri;
   } 
 
} 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:put
   @Override 
   public URI apply(String input) {
      Optional<CDNContainerApi> cdnExtension = sync.getCDNExtension();
      checkArgument(cdnExtension.isPresent(), "CDN is required, but the extension is not available!");
      URI uri = cdnExtension.get().enable(input);
      cdnContainer.put(input, uri);
      return uri;
   } 
 
} 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getIfPresent, put, refresh
        executor.shutdownNow();
    } 
 
    public NetworkLocation get(HostAddress host)
    { 
        NetworkLocation location = cache.getIfPresent(host);
        if ((location == null) && (negativeCache.getIfPresent(host) == null)) {
            // Store a value in the cache, so that refresh() is done asynchronously 
            cache.put(host, ROOT_LOCATION);
            cache.refresh(host);
        } 
        // Return the root location for anything we couldn't locate 
        return location == null ? ROOT_LOCATION : location;
    } 
 
    private NetworkLocation locate(HostAddress host)
    { 
        try { 
            return networkTopology.locate(host);
        } 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:get
   } 
 
   @Override 
   public Optional<String> apply(String bucket) {
      try { 
         return bucketToRegion.get(bucket);
      } catch (ExecutionException e) {
         logger.debug("error looking up region for bucket %s: %s", bucket, e);
      } catch (UncheckedExecutionException e) {
         logger.debug("error looking up region for bucket %s: %s", bucket, e);
      } catch (InvalidCacheLoadException e) {
         logger.trace("bucket %s not found: %s", bucket, e);
      } 
      return Optional.absent();
   } 
} 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getUnchecked
      this.lookupCache = CacheBuilder.newBuilder().build(new Loader(apiVersion));
   } 
 
   @Override 
   public Optional<Object> apply(InvocationSuccess input) {
      return lookupCache.getUnchecked(input);
   } 
 
} 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:put
      return region;
   } 
 
   public void endElement(String uri, String name, String qName) {
      region = fromValue(currentOrNull(currentText));
      bucketToRegion.put(bucket, Optional.fromNullable(region));
   } 
 
   @Override 
   public LocationConstraintHandler setContext(HttpRequest request) {
      super.setContext(request);
      setBucket(GeneratedHttpRequest.class.cast(getRequest()).getInvocation().getArgs().get(0).toString());
      return this;
   } 
 
   void setBucket(String bucket) {
      this.bucket = bucket;
   } 
 
   /** 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:get
   public NodeMetadata apply(NodeMetadata arg0) {
      String[] parts = AWSUtils.parseHandle(arg0.getId());
      String region = parts[0];
      String instanceId = parts[1];
      try { 
         String publicIp = cache.get(new RegionAndName(region, instanceId));
         // Replace existing public addresses with elastic IP (see note above) 
         return NodeMetadataBuilder.fromNodeMetadata(arg0)
                 .publicAddresses(ImmutableSet.<String> builder().add(publicIp).build()).build();
      } catch (CacheLoader.InvalidCacheLoadException e) {
         // no ip was found 
         return arg0;
      } catch (ExecutionException e) {
         throw Throwables.propagate(e);
      } 
   } 
 
} 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
See Code Examples for Guava LoadingCache Methods: