Skip to content

feat(client): add optional override default cache ttl capability for prompt caching #1249

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

cemasma
Copy link

@cemasma cemasma commented Jul 9, 2025

Summary
This PR enhances the Langfuse Python SDK’s prompt caching mechanism by enabling runtime overrides of the default 60-second TTL (default_cache_ttl_seconds). It allows developers to optionally specify a custom TTL—or disable caching entirely—during the initialization of the Langfuse client.

Goal

  • To allow users to control the default prompt cache config without specifying it for every get prompt request.
  • You can extend the cache to reduce API calls (e.g., set to 300 seconds) or you can disable caching by setting it to 0 for immediate prompt fetches every time at initial.

Important

Add capability to override default cache TTL for prompt caching in Langfuse Python SDK, with tests for custom TTL and caching behavior.

  • Behavior:
    • Adds default_cache_ttl_seconds parameter to Langfuse class in client.py to allow overriding the default cache TTL for prompts.
    • Supports disabling caching by setting TTL to 0.
  • Prompt Caching:
    • Updates PromptCache in prompt_cache.py to use default_cache_ttl_seconds if provided.
    • Modifies PromptCacheItem to respect the new TTL setting.
  • Tests:
    • Adds tests in test_prompt.py to verify custom TTL functionality, including overriding default TTL and disabling caching.
    • Tests ensure prompts are refetched when expired according to custom or default TTL.

This description was created by Ellipsis for ab08393. You can customize this summary. It will automatically update as commits are pushed.

Greptile Summary

Disclaimer: Experimental PR review

Adds capability to override default prompt cache TTL (60 seconds) during Langfuse client initialization, allowing global configuration of prompt caching behavior.

  • Added default_cache_ttl_seconds parameter to langfuse/_client/client.py for configuring cache duration at client level
  • Modified langfuse/_utils/prompt_cache.py to support custom TTL configuration with backward compatibility
  • Enhanced langfuse/_client/resource_manager.py to propagate TTL settings through the initialization chain
  • Added comprehensive test suite in tests/test_prompt.py verifying custom TTL behavior and cache expiration

@CLAassistant
Copy link

CLAassistant commented Jul 9, 2025

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4 files reviewed, 1 comment
Edit PR Review Bot Settings | Greptile

@cemasma cemasma force-pushed the add-override-default-cache-ttl-capability branch from ab08393 to 1e84c57 Compare July 9, 2025 23:34
@hassiebp hassiebp self-assigned this Jul 10, 2025
@cemasma cemasma force-pushed the add-override-default-cache-ttl-capability branch 4 times, most recently from 26baec6 to 2aa1c48 Compare July 16, 2025 22:53
@cemasma cemasma force-pushed the add-override-default-cache-ttl-capability branch from 2aa1c48 to e7fe63a Compare July 22, 2025 22:22
@cemasma cemasma force-pushed the add-override-default-cache-ttl-capability branch from 29333d7 to 178645f Compare July 25, 2025 20:55
@hassiebp hassiebp self-requested a review July 28, 2025 12:52
@hassiebp hassiebp removed their assignment Jul 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants