Honor a default_cache_ttl_seconds of 0 in Prompts - #873
Open
ckarnell wants to merge 1 commit into
Open
Conversation
Radu-Raicea
approved these changes
Aug 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
--- LETTER BELOW THIS LINE ---
Prompts.__init__resolves the default cache TTL withdefault_cache_ttl_seconds or DEFAULT_CACHE_TTL_SECONDS, so passing0is treated as if nothing was passed and the value becomes 300.0is a meaningful setting here, and the same class already honors it on the other path._get_internalresolves the per-call TTL withcache_ttl_seconds if cache_ttl_seconds is not None else ..., andis_fresh = (now - fetched_at) < ttlwithttl=0means "never serve from cache". So the per-call option lets you disable caching with0while the constructor default silently cannot.Measured against the library, with no network:
Prompts(default_cache_ttl_seconds=0)reports a TTL of 300. Counting fetch attempts against a seeded cache, the constructor0serves from cache (0 fetches) identically to passing no TTL at all, while the per-callget(cache_ttl_seconds=0)correctly refetches.The fix matches the per-call form, +3/-1:
I added a regression test that fails on the current code (
AssertionError: 1 != 2) and passes with the fix. The existing suite is 68 passing before and 69 after, so this path was never covered. They test a TTL of 60. Never 0.Nonestill yields 300 and default behavior does not change.I did not run against a live PostHog instance, so all measurements use the repo's mocked session or a seeded cache.