Repository navigation
fix: honor updated TTL when overwriting feature cache entries - #145
fallintoplace wants to merge 2 commits into
Conversation
|
|
|
||
| def set(self, key: str, value: Dict[str, Any], ttl: int) -> None: | ||
| if key in self.cache: | ||
| self.cache[key].ttl = ttl |
There was a problem hiding this comment.
When two clients refresh the same cache key at the same time with different TTLs, one can change entry.ttl before the other calls update(). For example, a refresh requesting a five-second TTL can store its value with a 600-second expiry instead. Those features may remain cached long after the requested five seconds. Keep each refreshed value paired with its own TTL and expiry.
Knowledge Base Used: Client lifecycle and feature refresh
Prompt To Fix With AI
This is a comment left during a code review.
Path: growthbook/growthbook.py
Line: 120
Comment:
**Concurrent refreshes mix TTLs**
When two clients refresh the same cache key at the same time with different TTLs, one can change `entry.ttl` before the other calls `update()`. For example, a refresh requesting a five-second TTL can store its value with a 600-second expiry instead. Those features may remain cached long after the requested five seconds. Keep each refreshed value paired with its own TTL and expiry.
**Knowledge Base Used:** [Client lifecycle and feature refresh](https://app.greptile.com/growthbook/-/custom-context/knowledge-base/growthbook/growthbook-python/-/docs/client-lifecycle-and-feature-refresh.md)
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.|
Heads-up: this overlaps with #114, which adds a An alternative that fixes it independently of #114, and keeps the signature def update(self, value: Dict[str, Any], ttl: Optional[int] = None) -> None:
if ttl is not None:
self.ttl = ttl
self.value = value
self.expires = time() + self.ttl
Then set() stays a single call and each refreshed value is paired with its own
TTL by construction. |
What
Why
Implementation