用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/Lord1Egypt/ai-skillforge --skill context-caching命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
Implementing WCAG accessibility guidelines, semantic HTML5, and screen reader ARIA roles.
How to use the Adaptyv Bio Foundry API and Python SDK for protein experiment design, submission, and results retrieval. Use this skill whenever the user mentions Adaptyv, Foundry API, protein binding assays, protein screening experiments, BLI/SPR assays, thermostability assays, or wants to submit protein sequences for experimental characterization. Also trigger when code imports `adaptyv`, `adaptyv_sdk`, or `FoundryClient`, or references `foundry-api-public.adaptyvbio.com`.
This skill should be used for time series machine learning tasks including classification, regression, clustering, forecasting, anomaly detection, segmentation, and similarity search. Use when working with temporal data, sequential patterns, or time-indexed observations requiring specialized algorithms beyond standard ML approaches. Particularly suited for univariate and multivariate time series analysis with scikit-learn compatible APIs.
基于 SOC 职业分类
正在显示 SKILL.md
| name | context-caching |
| description | Large context caching, cached token management, TTL config, and cost optimization. |
| allowed-tools | Read Write Edit Bash |
| license | MIT license |
| metadata | {"skill-author":"Lord1Egypt"} |
This skill implements Gemini's native Context Caching API. Context Caching allows you to upload large, reusable pieces of data (e.g. video files, massive directories of text, or large PDFs) to Google's servers once, cache the parsed tokens, and query them multiple times.
Caching significantly reduces both query latency and per-request token costs when dealing with contents larger than 32,768 tokens (up to 2 million tokens).
import time
from google import genai
# Initialize the Gemini GenAI Client
client = genai.Client()
def create_and_use_cache(document_path: str):
print("Uploading target file for context caching...")
doc_file = client.files.upload(file=document_path)
# Wait for file to become active
while doc_file.state.name == "PROCESSING":
time.sleep(2)
doc_file = client.files.get(name=doc_file.name)
print(f"Creating Gemini Context Cache for: {doc_file.name}...")
# Create the cache
cache = client.caches.create(
model='gemini-2.5-flash',
config=dict(
# Pass the files or text contents to cache
contents=[doc_file],
# Time to live (TTL) before the cache expires automatically
ttl='300s', # 5 minutes
# Provide a descriptive name/label for management
display_name="large_document_reference_cache"
)
)
print(f"Cache created successfully! Cache Name: {cache.name}")
print(f"Expires at: {cache.expire_time}")
# Query using the cached content
print("\nQuerying Gemini using the cache token bank...")
response1 = client.models.generate_content(
model='gemini-2.5-flash',
contents="Summarize Section 3 of the document.",
config=dict(
# Link the query to the cache resource name
cached_content=cache.name
)
)
print("Response 1:", response1.text)
# Run a second query (reuses the cache, saving time and tokens)
response2 = client.models.generate_content(
model='gemini-2.5-flash',
contents="Extract all dates mentioned in the text.",
config=dict(
cached_content=cache.name
)
)
print("\nResponse 2:", response2.text)
# Cleanup: Delete the cache token bank
print("\nCleaning up cache...")
client.caches.delete(name=cache.name)
client.files.delete(name=doc_file.name)
if __name__ == "__main__":
# Create a dummy file for demonstration
with open("temp_large_doc.txt", "w") as f:
f.write("Section 1: Intro. Section 2: General Rules. Section 3: Analysis of results from 2026-06-04.")
create_and_use_cache("temp_large_doc.txt")
You can inspect the cache size, verify token details, and update the time-to-live expiration dynamically:
# Retrieve active cache information
my_cache = client.caches.get(name=cache.name)
print(f"Cached tokens count: {my_cache.metadata.total_token_count}")
# Extend cache lifetime by resetting the TTL
client.caches.patch(
name=cache.name,
config=dict(
ttl='600s' # Extend by another 10 minutes
)
)
google-genai>=0.1.1