Repository navigation
Commit 9eb64e5
authored
feat(runtime): controls for the HTTP module cache (#620)
* refactor(runtime): fetch synchronous-fallback modules through the loader's session
The resolver's synchronous fallback fetched with +[NSURLConnection
sendSynchronousRequest:], which goes through the app's shared NSURLCache.
It now issues its request on the same NSURLSession as the module-graph
walk, so both paths read and write one HTTP cache, and blocks on a
semaphore for at most the request timeout plus five seconds per attempt.
A wait that runs out cancels the task and fails the import with
"(no response within Ns)", without the transport retry.
The fallback runs when the graph walk could not fetch a dependency: the
walk leaves dependency failures to the resolver. A new test route answers
a dependency's first request with 503, so the resolver fetches it
synchronously inside InstantiateModule, on the iOS main thread after
UIApplicationMain. Nested synchronous fetches in that position, over
keep-alive connections, all completed on the iOS 26.3 simulator; the
NSURLSession hang recorded for that position did not reproduce.
* feat(runtime): switch and clear the HTTP module cache
The loader's HTTP cache can now be turned off and cleared, process-wide
(the main isolate and every worker):
- ns:module setHttpCacheEnabled(enabled) and clearHttpCache(), in Debug
and Release. A non-boolean argument to setHttpCacheEnabled throws a
TypeError.
- Launch arguments --nativescript-no-module-cache (start with the cache
off) and --nativescript-clear-module-cache (clear it before the first
fetch).
- App config key "moduleHttpCache" (top level): false starts with the
cache off.
Off means the Fetch no-store mode: nothing is read from or written to
the cache, requests go through a session without a URLCache, ignore
local cache data and carry Cache-Control: no-cache and Pragma: no-cache.
The switch is read when each fetch is issued, by the graph walk and the
synchronous fallback alike; fetches in flight are unaffected. Launch
arguments and the config key are read once per process.
The cache is now partitioned by origin (the URL-standard origin from
ada, used only for this): one session and NSURLCache directory per
origin under Library/Caches/ns-module-http-cache/origins, opened on
first use. A clear moves the directory into a trash directory emptied in
the background and opens the next generation, instead of calling
removeAllCachedResponses: after removeAllCachedResponses and an
immediate kill, the next launch still found the entry on disk. The
flat cache files the previous layout kept at the root are removed at
the first fetch.
* feat(runtime): honour Clear-Site-Data on HTTP module responses
A module response carrying Clear-Site-Data with "cache" or "*" (a
comma-separated list of quoted strings; other directives are ignored)
clears the loader's HTTP cache for the origin of the response URL. It
is applied in the fetch completion, before the response reaches the
graph walk or the synchronous fallback, so nothing requested afterwards
comes from the old cache. Plain http: origins are honoured too.
The partition the response was fetched through is dropped with it, which
also covers a redirect across origins: the carrier is stored there, and
kept it would be replayed from the cache and clear again on every hit.
The header is therefore acted on once per network response. A 304 that
carries it reaches the loader too: on the iOS 26.3 simulator, a
revalidation answered by such a 304 cleared the origin's cache.
* feat(inspector): Network.setCacheDisabled and clearBrowserCache control the module cache
Network.setCacheDisabled {cacheDisabled} records the state for the
sending connection; the loader's HTTP cache is off while any connected
frontend has it disabled, and a connection's state ends when it
disconnects. Network.clearBrowserCache clears the loader's cache for
every origin.
Both take effect on the inspector socket thread as the message arrives,
so they work while an isolate is paused and from worker sessions. A
main-session message then continues to the JS Network domain handler as
before, whose reply is the frontend's answer, so app handlers (such as
@nativescript/core's) still run; without a handler the runtime replies
{} instead of V8's method-not-found. Worker sessions have no JS domain
handlers and get {} from the socket thread. A setCacheDisabled without
a boolean cacheDisabled changes nothing and, when no handler answers it,
gets an Invalid parameters error.
* feat(runtime): bound the HTTP module cache to the most recently used origins
Every new dev-server address or port is a new origin and so a new cache
partition, which nothing removed. Opening an origin's cache now stamps
its directory's modification date, and the one-time initialisation,
before any session exists, keeps the 8 most recently opened origin
directories and moves the rest to trash. A directory whose date cannot
be read counts as the oldest. Origins opened later in the same process
are not pruned until the next launch.
The docs mention the bound with the on-disk layout and no longer carry
the platform note.
* fix(inspector): leave the module cache alone for unknown worker sessions
Network.setCacheDisabled and Network.clearBrowserCache sent with a
sessionId applied their process-wide effect and replied {} whatever the
session was. They now act only when the sessionId names a worker session
the connection can reach, by the same test RouteToWorker uses; for any
other sessionId, a made-up one or that of a worker that terminated,
nothing changes and the routing answers "Session not found", as for any
other method. The registry lock is released before the cache is called.
The docs also state a limitation: a module reached through a redirect
from another origin is cached with the origin the import requested, so a
Clear-Site-Data from the serving origin does not remove it, while
clearHttpCache(), the launch argument and Network.clearBrowserCache do.
* perf(runtime): give the synchronous fallback its own sessions over the same cache
The resolver's synchronous fallback shared the graph walk's session, so
with every connection to a host held by walk fetches it waited for one
to free up while blocking the JS thread. Each origin partition now has
two sessions configured alike over its one NSURLCache instance: one for
the graph walk and one, created on first use, for the synchronous
fallback. With the cache off, each path likewise has its own uncached
session. StartModuleFetchTask takes the path asking and stays the only
place requests are issued, so the switch, clears, Clear-Site-Data and
the origin bound apply to both, and dropping a partition retires both
sessions. A response stored by either path is read by the other.1 parent 93de8cc commit 9eb64e5
15 files changed
Lines changed: 1495 additions & 248 deletions
File tree
- NativeScript
- inspector
- runtime
- js
- TestRunnerTests
- TestRunner/app/tests
- docs
- types
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
185 | 185 | | |
186 | 186 | | |
187 | 187 | | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
188 | 191 | | |
189 | 192 | | |
190 | 193 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
| |||
213 | 214 | | |
214 | 215 | | |
215 | 216 | | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
216 | 229 | | |
217 | 230 | | |
218 | 231 | | |
| |||
419 | 432 | | |
420 | 433 | | |
421 | 434 | | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
422 | 438 | | |
423 | 439 | | |
424 | 440 | | |
| |||
498 | 514 | | |
499 | 515 | | |
500 | 516 | | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
501 | 544 | | |
502 | 545 | | |
503 | 546 | | |
| |||
685 | 728 | | |
686 | 729 | | |
687 | 730 | | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
688 | 736 | | |
689 | 737 | | |
690 | 738 | | |
| |||
986 | 1034 | | |
987 | 1035 | | |
988 | 1036 | | |
| 1037 | + | |
| 1038 | + | |
| 1039 | + | |
| 1040 | + | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
| 1044 | + | |
| 1045 | + | |
| 1046 | + | |
| 1047 | + | |
| 1048 | + | |
| 1049 | + | |
| 1050 | + | |
| 1051 | + | |
989 | 1052 | | |
990 | 1053 | | |
991 | 1054 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
| |||
84 | 85 | | |
85 | 86 | | |
86 | 87 | | |
87 | | - | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
88 | 92 | | |
89 | 93 | | |
90 | 94 | | |
| |||
108 | 112 | | |
109 | 113 | | |
110 | 114 | | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
115 | 120 | | |
116 | 121 | | |
117 | 122 | | |
| |||
145 | 150 | | |
146 | 151 | | |
147 | 152 | | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
148 | 176 | | |
0 commit comments