Get information about a specific context cache, such as its creation time and expiration time.

## Code sample

### C#


Before trying this sample, follow the C# setup instructions in the
[Vertex AI quickstart using
client libraries](https://docs.cloud.google.com/vertex-ai/docs/start/client-libraries).


For more information, see the
[Vertex AI C# API
reference documentation](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.AIPlatform.V1/latest).


To authenticate to Vertex AI, set up Application Default Credentials.
For more information, see

[Set up authentication for a local development environment](https://docs.cloud.google.com/docs/authentication/set-up-adc-local-dev-environment).


    using https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.AIPlatform.V1Beta1/latest/Google.Cloud.AIPlatform.V1Beta1.html;
    using System;
    using System.Threading.Tasks;

    public class GetContextCache
    {
        public async Task<CachedContent> Get(https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.AIPlatform.V1Beta1/latest/Google.Cloud.AIPlatform.V1Beta1.CachedContentName.html name)
        {
            var client = await new https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.AIPlatform.V1Beta1/latest/Google.Cloud.AIPlatform.V1Beta1.GenAiCacheServiceClientBuilder.html
            {
                Endpoint = "us-central1-aiplatform.googleapis.com"
            }.BuildAsync();

            var cachedContent = await client.GetCachedContentAsync(new https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.AIPlatform.V1Beta1/latest/Google.Cloud.AIPlatform.V1Beta1.GetCachedContentRequest.html
            {
                CachedContentName = name
            });

            Console.WriteLine($"Get cache: {cachedContent.Name}");
            return cachedContent;
        }
    }

### Go


Before trying this sample, follow the Go setup instructions in the
[Vertex AI quickstart using
client libraries](https://docs.cloud.google.com/vertex-ai/docs/start/client-libraries).


For more information, see the
[Vertex AI Go API
reference documentation](https://docs.cloud.google.com/go/docs/reference/cloud.google.com/go/aiplatform/latest/apiv1).


To authenticate to Vertex AI, set up Application Default Credentials.
For more information, see

[Set up authentication for a local development environment](https://docs.cloud.google.com/docs/authentication/set-up-adc-local-dev-environment).

    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.https://docs.cloud.google.com/go/docs/reference/cloud.google.com/go/vertexai/latest/genai.html#cloud_google_com_go_vertexai_genai_Client_NewClient(ctx, projectID, location)
    	if err != nil {
    		return fmt.Errorf("unable to create client: %w", err)
    	}
    	defer client.https://docs.cloud.google.com/go/docs/reference/cloud.google.com/go/vertexai/latest/genai.html#cloud_google_com_go_vertexai_genai_Client_Close()

    	cachedContent, err := client.https://docs.cloud.google.com/go/docs/reference/cloud.google.com/go/vertexai/latest/genai.html#cloud_google_com_go_vertexai_genai_Client_GetCachedContent(ctx, contentName)
    	if err != nil {
    		return fmt.Errorf("GetCachedContent: %w", err)
    	}
    	fmt.Fprintf(w, "Retrieved cached content %q", cachedContent.https://docs.cloud.google.com/go/docs/reference/cloud.google.com/go/vertexai/latest/genai.html#cloud_google_com_go_vertexai_genai_GenerativeModel_Name)
    	return nil
    }

## What's next


To search and filter code samples for other Google Cloud products, see the
[Google Cloud sample browser](https://docs.cloud.google.com/docs/samples?product=generativeaionvertexai).