Method: projects.locations.cachedContents.get

Gets cached content configurations

Endpoint

get https: / /{endpoint} /v1beta1 /{name}

Where {service-endpoint} is one of the supported service endpoints .

Path parameters

name string

Required. The resource name referring to the cached content

Request body

The request body must be empty.

Example request

C#

  using 
  
 Google.Cloud.AIPlatform.V1Beta1 
 ; 
 using 
  
 System 
 ; 
 using 
  
 System.Threading.Tasks 
 ; 
 public 
  
 class 
  
 GetContextCache 
 { 
  
 public 
  
 async 
  
 Task<CachedContent> 
  
 Get 
 ( 
 CachedContentName 
  
 name 
 ) 
  
 { 
  
 var 
  
 client 
  
 = 
  
 await 
  
 new 
  
 GenAiCacheServiceClientBuilder 
  
 { 
  
 Endpoint 
  
 = 
  
 "us-central1-aiplatform.googleapis.com" 
  
 }. 
 BuildAsync 
 (); 
  
 var 
  
 cachedContent 
  
 = 
  
 await 
  
 client 
 . 
 GetCachedContentAsync 
 ( 
 new 
  
 GetCachedContentRequest 
  
 { 
  
 CachedContentName 
  
 = 
  
 name 
  
 }); 
  
 Console 
 . 
 WriteLine 
 ( 
 $"Get cache: {cachedContent.Name}" 
 ); 
  
 return 
  
 cachedContent 
 ; 
  
 } 
 } 
  
 

Go

  import 
  
 ( 
  
 "context" 
  
 "fmt" 
  
 "io" 
  
 "cloud.google.com/go/vertexai/genai" 
 ) 
 // getContextCache shows how to retrieve the metadata of a cached content 
 // contentName is the ID of the cached content to retrieve 
 func 
  
 getContextCache 
 ( 
 w 
  
 io 
 . 
 Writer 
 , 
  
 contentName 
  
 string 
 , 
  
 projectID 
 , 
  
 location 
  
 string 
 ) 
  
 error 
  
 { 
  
 // location := "us-central1" 
  
 ctx 
  
 := 
  
 context 
 . 
 Background 
 () 
  
 client 
 , 
  
 err 
  
 := 
  
 genai 
 . 
 NewClient 
 ( 
 ctx 
 , 
  
 projectID 
 , 
  
 location 
 ) 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 return 
  
 fmt 
 . 
 Errorf 
 ( 
 "unable to create client: %w" 
 , 
  
 err 
 ) 
  
 } 
  
 defer 
  
 client 
 . 
 Close 
 () 
  
 cachedContent 
 , 
  
 err 
  
 := 
  
 client 
 . 
 GetCachedContent 
 ( 
 ctx 
 , 
  
 contentName 
 ) 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 return 
  
 fmt 
 . 
 Errorf 
 ( 
 "GetCachedContent: %w" 
 , 
  
 err 
 ) 
  
 } 
  
 fmt 
 . 
 Fprintf 
 ( 
 w 
 , 
  
 "Retrieved cached content %q" 
 , 
  
 cachedContent 
 . 
 Name 
 ) 
  
 return 
  
 nil 
 } 
  
 

Python

  import 
 vertexai 
 from 
 vertexai.preview 
 import 
 caching 
 # TODO(developer): Update and un-comment below lines 
 # PROJECT_ID = "your-project-id" 
 # cache_id = "your-cache-id" 
 vertexai 
 . 
 init 
 ( 
 project 
 = 
 PROJECT_ID 
 , 
 location 
 = 
 "us-central1" 
 ) 
 cached_content 
 = 
 caching 
 . 
 CachedContent 
 ( 
 cached_content_name 
 = 
 cache_id 
 ) 
 print 
 ( 
 cached_content 
 . 
 resource_name 
 ) 
 # Example response: 
 # projects/[PROJECT_ID]/locations/us-central1/cachedContents/1234567890  
 
 

Response body

If successful, the response body contains an instance of CachedContent .