1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
//! Widget view cache for composite widgets that opt in via
//! [`Widget::cache_key`][crate::widget::Widget::cache_key].
//!
//! Mirrors the widget view cache pattern already present in the
//! Elixir, Gleam, TypeScript, and Ruby SDKs: when a widget's
//! `cache_key(props, state)` returns the same hash between renders,
//! the previously-expanded view tree is reused and `view()` is not
//! re-invoked. Widgets that don't override `cache_key` (the default
//! returns `None`) bypass the cache entirely, keeping the default
//! path identical to the pre-cache behaviour.
//!
//! Owned by the app runner (direct mode, test session) alongside
//! [`WidgetStateStore`][crate::widget::WidgetStateStore] and
//! [`MemoCache`][super::memo_cache::MemoCache]. Keyed by the widget's
//! scoped ID so two widget placements that happen to hash to the
//! same cache key don't collide.
//!
//! Stale entries are pruned at the end of each render via
//! [`WidgetViewCache::finish_cycle`]: [`WidgetViewCache::begin_cycle`]
//! resets the live-set at the start, [`WidgetViewCache::mark_live`]
//! records every widget touched during the render, and `finish_cycle`
//! evicts anything not in that set. Mirrors the live-IDs pattern used
//! by `MemoCache`.
use ;
use TreeNode;
/// Per-render widget-view cache.
///
/// Entry is `(cache_key_hash, expanded_view)`. A hit only needs to
/// compare the stored hash against the incoming widget's cache-key
/// hash; on match, the cached expanded view is dropped in and
/// `W::view()` is skipped.
pub