set ComputedVar cache default to False#5968
Conversation
Greptile OverviewGreptile SummaryThis PR changes the default caching behavior for computed variables from The change updates five locations in Important Files Changed
Confidence score: 4/5
Sequence DiagramsequenceDiagram
participant User
participant State
participant ComputedVar
participant Cache
User->>State: "@rx.var decorator on method"
State->>ComputedVar: "__init__(cache=False by default)"
ComputedVar->>ComputedVar: "Set _cache = False"
ComputedVar->>State: "Return ComputedVar instance"
User->>State: "Access computed var property"
State->>ComputedVar: "__get__(instance, owner)"
alt cache=False (new default)
ComputedVar->>ComputedVar: "Call fget() directly"
ComputedVar->>ComputedVar: "No caching logic"
ComputedVar->>State: "Return fresh computed value"
else cache=True (explicit)
ComputedVar->>Cache: "Check if cached value exists"
alt Cache hit
Cache->>ComputedVar: "Return cached value"
else Cache miss
ComputedVar->>ComputedVar: "Call fget()"
ComputedVar->>Cache: "Store result in cache"
ComputedVar->>State: "Return computed value"
end
end
State->>User: "Return computed value"
|
|
reflex-dev/reflex-web#1687 |
CodSpeed Performance ReportMerging #5968 will not alter performanceComparing Summary
|
|
the intention is for |
Description
This PR changes the default value of the
cacheparameter inComputedVarfromTruetoFalseto align with the documented behavior at https://reflex.dev/docs/vars/computed-vars#cached-vars.Background
According to the documentation:
@rx.varshould recompute on every state change (cache=False behavior)@rx.var(cache=True)should only recompute when dependencies change (cached behavior)However, the current implementation has
cache=Trueas the default in thecomputed_var()function andComputedVar.__init__(), which contradicts the documentation.Changes
Updated the default
cacheparameter toFalse.Related Issues
This change makes the code consistent with the documentation. As a result, PR in reflex-web (which updates the documentation to state that the default is
True) should be declined, as the code now correctly implementscache=Falseas the default behavior.Breaking Change
Existing computed vars that relied on the default caching behavior will no longer be cached automatically. Users who want caching enabled must now explicitly set
@rx.var(cache=True).Migration Guide
If you have existing code using computed vars that depends on caching: