Storage Control List Anywhere Caches

Storage Control List Anywhere Caches

Explore further

For detailed documentation that includes this code sample, see the following:

Code sample

C++

For more information, see the Cloud Storage C++ API reference documentation .

To authenticate to Cloud Storage, set up Application Default Credentials. For more information, see Set up authentication for client libraries .

  namespace 
  
 storagecontrol 
  
 = 
  
 google 
 :: 
 cloud 
 :: 
 storagecontrol_v2 
 ; 
 []( 
 storagecontrol 
 :: 
 StorageControlClient 
  
 client 
 , 
  
 std 
 :: 
 string 
  
 const 
&  
 bucket_name 
 ) 
  
 { 
  
 auto 
  
 const 
  
 parent 
  
 = 
  
 std 
 :: 
 string 
 { 
 "projects/_/buckets/" 
 } 
  
 + 
  
 bucket_name 
 ; 
  
 for 
  
 ( 
 auto 
  
 anywhere_cache 
  
 : 
  
 client 
 . 
 ListAnywhereCaches 
 ( 
 parent 
 )) 
  
 { 
  
 if 
  
 ( 
 ! 
 anywhere_cache 
 ) 
  
 throw 
  
 std 
 :: 
 move 
 ( 
 anywhere_cache 
 ). 
 status 
 (); 
  
 std 
 :: 
 cout 
 << 
 anywhere_cache 
 - 
> name 
 () 
 << 
 " 
 \n 
 " 
 ; 
  
 } 
 } 
 

Java

For more information, see the Cloud Storage Java API reference documentation .

To authenticate to Cloud Storage, set up Application Default Credentials. For more information, see Set up authentication for client libraries .

  import 
  
 com.google.storage.control.v2. AnywhereCache 
 
 ; 
 import 
  
 com.google.storage.control.v2. BucketName 
 
 ; 
 import 
  
 com.google.storage.control.v2. ListAnywhereCachesRequest 
 
 ; 
 import 
  
 com.google.storage.control.v2. StorageControlClient 
 
 ; 
 import 
  
 com.google.storage.control.v2. StorageControlClient 
. ListAnywhereCachesPagedResponse 
 
 ; 
 import 
  
 java.io.IOException 
 ; 
 public 
  
 final 
  
 class 
 AnywhereCacheList 
  
 { 
  
 public 
  
 static 
  
 void 
  
 anywhereCacheList 
 ( 
 String 
  
 bucketName 
 ) 
  
 throws 
  
 IOException 
  
 { 
  
 try 
  
 ( 
  StorageControlClient 
 
  
 storageControl 
  
 = 
  
  StorageControlClient 
 
 . 
 create 
 ()) 
  
 { 
  
  ListAnywhereCachesRequest 
 
  
 request 
  
 = 
  
  ListAnywhereCachesRequest 
 
 . 
 newBuilder 
 () 
  
 . 
 setParent 
 ( 
  BucketName 
 
 . 
 format 
 ( 
 "_" 
 , 
  
 bucketName 
 )) 
  
 . 
 build 
 (); 
  
  ListAnywhereCachesPagedResponse 
 
  
 page 
  
 = 
  
 storageControl 
 . 
 listAnywhereCaches 
 ( 
 request 
 ); 
  
 for 
  
 ( 
  AnywhereCache 
 
  
 anywhereCache 
  
 : 
  
 page 
 . 
 iterateAll 
 ()) 
  
 { 
  
 System 
 . 
 out 
 . 
 println 
 ( 
 anywhereCache 
 . 
 getName 
 ()); 
  
 } 
  
 } 
  
 } 
 } 
 

PHP

For more information, see the Cloud Storage PHP API reference documentation .

To authenticate to Cloud Storage, set up Application Default Credentials. For more information, see Set up authentication for client libraries .

  use Google\Cloud\Storage\Control\V2\Client\StorageControlClient; 
 use Google\Cloud\Storage\Control\V2\ListAnywhereCachesRequest; 
 /** 
 * Lists Anywhere Cache instances for a given bucket. 
 * 
 * @param string $bucketName The name of your Cloud Storage bucket. 
 *        (e.g. 'my-bucket') 
 */ 
 function list_anywhere_caches(string $bucketName): void 
 { 
 $storageControlClient = new StorageControlClient(); 
 // Set project to "_" to signify global bucket 
 $formattedName = $storageControlClient->bucketName('_', $bucketName); 
 $request = new ListAnywhereCachesRequest([ 
 'parent' => $formattedName, 
 ]); 
 $response = $storageControlClient->listAnywhereCaches($request); 
 foreach ($response as $anywhereCache) { 
 printf('Anywhere cache name: %s' . PHP_EOL, $anywhereCache->getName()); 
 } 
 } 
 

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser .

Create a Mobile Website
View Site in Mobile | Classic
Share by: