/** This function may return cached copies of GoogleCloudStorageItemInfo. */ @Override public GoogleCloudStorageItemInfo getItemInfo(StorageResourceId resourceId) throws IOException { // Get the item from cache. GoogleCloudStorageItemInfo item = cache.getItem(resourceId); // If it wasn't in the cache, request it then add it. if (item == null) { item = super.getItemInfo(resourceId); cache.putItem(item); } return item; }
/** This function may return cached copies of GoogleCloudStorageItemInfo. */ @Override public List<GoogleCloudStorageItemInfo> getItemInfos(List<StorageResourceId> resourceIds) throws IOException { List<GoogleCloudStorageItemInfo> result = new ArrayList<GoogleCloudStorageItemInfo>(resourceIds.size()); List<StorageResourceId> request = new ArrayList<StorageResourceId>(resourceIds.size()); // Populate the result list with items in the cache, and the request list with resources that // still need to be resolved. Null items are added to the result list to preserve ordering. for (StorageResourceId resourceId : resourceIds) { GoogleCloudStorageItemInfo item = cache.getItem(resourceId); if (item == null) { request.add(resourceId); } result.add(item); } // Resolve all the resources which were not cached, cache them, and add them to the result list. // Null entries in the result list are replaced by the fresh entries from the underlying // GoogleCloudStorage. if (!request.isEmpty()) { List<GoogleCloudStorageItemInfo> response = super.getItemInfos(request); Iterator<GoogleCloudStorageItemInfo> responseIterator = response.iterator(); // Iterate through the result set, replacing the null entries added previously with entries // from the response. for (int i = 0; i < result.size() && responseIterator.hasNext(); i++) { if (result.get(i) == null) { GoogleCloudStorageItemInfo item = responseIterator.next(); cache.putItem(item); result.set(i, item); } } } return result; }