-
Notifications
You must be signed in to change notification settings - Fork 226
clarify rx.var cache defaults to True #1687
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
base: main
Are you sure you want to change the base?
Conversation
Greptile OverviewGreptile SummaryThis PR fixes a critical documentation issue in the computed vars guide. The primary problem was that the The changes clarify that This fix ensures the documentation accurately reflects the framework's behavior and provides working examples that developers can rely on. Important Files Changed
Confidence score: 5/5
Sequence DiagramsequenceDiagram
participant User
participant Frontend
participant "State Management"
participant "Computed Var Cache"
User->>Frontend: "Types in input box"
Frontend->>Frontend: "Input value changes"
User->>Frontend: "Clicks out (blur event)"
Frontend->>"State Management": "set_text(value)"
"State Management"->>"State Management": "self.text = value"
"State Management"->>"Computed Var Cache": "Check if upper_text cache invalid"
"Computed Var Cache"->>"State Management": "Cache invalid (text changed)"
"State Management"->>"State Management": "Recompute upper_text()"
"State Management"->>"State Management": "return self.text.upper()"
"State Management"->>"Computed Var Cache": "Update cached result"
"State Management"->>Frontend: "State update with new upper_text"
Frontend->>User: "Display updated uppercase text"
Note over User, "Computed Var Cache": Default cache=True behavior
User->>Frontend: "Clicks Increment A button"
Frontend->>"State Management": "increment_a()"
"State Management"->>"State Management": "self.counter_a += 1"
"State Management"->>"Computed Var Cache": "Check last_touch_time (cache=False)"
"Computed Var Cache"->>"State Management": "Always recompute (no cache)"
"State Management"->>"State Management": "Get current time"
"State Management"->>"Computed Var Cache": "Check last_counter_a_update dependencies"
"Computed Var Cache"->>"State Management": "counter_a changed, recompute"
"State Management"->>"State Management": "Generate timestamp with counter_a"
"State Management"->>Frontend: "State update with new values"
Frontend->>User: "Display updated counters and timestamps"
Note over User, "Computed Var Cache": Cached vs non-cached var behavior
User->>Frontend: "Clicks Change User button"
Frontend->>"State Management": "change_user()"
"State Management"->>"State Management": "self.user_id = (self.user_id % 3) + 1"
"State Management"->>"Computed Var Cache": "Check async user_data dependencies"
"Computed Var Cache"->>"State Management": "user_id changed, recompute async var"
"State Management"->>"State Management": "await asyncio.sleep(1)"
"State Management"->>"State Management": "Fetch user data based on user_id"
"State Management"->>"Computed Var Cache": "Cache async result"
"State Management"->>Frontend: "State update with new user_data"
Frontend->>User: "Display updated user information"
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1 file reviewed, no comments
|
reflex-dev/reflex#5968 |
|
Examples that do not work can cause misunderstandings about the feature, so they must be corrected. |
Changes
cache=Trueis the default behavior for@rx.varlast_touch_timewas not working as expected@rx.varto@rx.var(cache=False)to recompute on every state updatecache=False@rx.cached_varusageIssue
The previous documentation and example at line 56 didn't work correctly because:
last_touch_timeused@rx.varwithout specifyingcache=False