def test_cache_update()

in python/cache.py [0:0]


    def test_cache_update(self):
        # [START cache_update]
        from google import genai
        from google.genai import types
        import datetime

        client = genai.Client()
        document = client.files.upload(file=media / "a11.txt")
        model_name = "gemini-1.5-flash-001"

        cache = client.caches.create(
            model=model_name,
            config={
                "contents": [document],
                "system_instruction": "You are an expert analyzing transcripts.",
            },
        )

        # Update the cache's time-to-live (ttl)
        ttl = f"{int(datetime.timedelta(hours=2).total_seconds())}s"
        client.caches.update(
            name=cache.name, config=types.UpdateCachedContentConfig(ttl=ttl)
        )
        print(f"After update:\n {cache}")

        # Alternatively, update the expire_time directly
        # Update the expire_time directly in valid RFC 3339 format (UTC with a "Z" suffix)
        expire_time = (
            (
                datetime.datetime.now(datetime.timezone.utc)
                + datetime.timedelta(minutes=15)
            )
            .isoformat()
            .replace("+00:00", "Z")
        )
        client.caches.update(
            name=cache.name,
            config=types.UpdateCachedContentConfig(expire_time=expire_time),
        )
        # [END cache_update]
        client.caches.delete(name=cache.name)