Enable Prompt Template Caching
masterThe SDK can cache fetched prompt templates in memory to speed up repeat reads and provide fallback during API failures.
- Enablement: Set
cache_ttl_seconds > 0when creating the client. - Scope: Applies to templates fetched via
client.templates.get(...). - Bypassing: Requests with
metadata_filtersormodel_parameter_overridesbypass the cache. - Limitations: Templates requiring server-side rendering (e.g., placeholder messages or tool-variable expansion) are not cached for local rendering.
- Invalidation: Use
client.invalidate(...)orclient.templates.invalidate(...)to clear entries.
# Example of enabling caching
pl = PromptLayer(api_key="pl_xxxxx", cache_ttl_seconds=3600)