Webapi with Hub-Cleanup Assistance Pattern
any of the index key should be registerForCleanup. i.e. any of indexXxx should follow the registerForCleanup.
clean the indexed key which indexed by the host component in beforeUnmount. And so that the component doesn't clean the key that doesn't create by the component itself.
The hub and the web-api removal cover different exits. Common/CleanupHub.cs keeps its key registry
in a static dictionary bucketed by connection id (SignalR builds a fresh hub instance for every
invocation, so an instance field could not carry a key from Add to the disconnect). When a
connection drops, its bucket is swept 90 seconds later: every key it registered is evicted unless a
live connection holds the same key by then — the composable registers all its keys again on
reconnect (and once its connection first comes up, for keys registered while it was still
starting), so a transient network drop costs the page nothing, while a closed tab frees its keys
without any client call. A key that drops twice within the grace belongs to the later sweep, so the
earlier one cannot evict it out from under a page that reconnected in between. The index-remove
calls wwwroot-src/src/composables/useCleanupHub.ts makes — on unmount and on every key
replacement — cover what the sweep cannot: a key replaced while the page stays up, and a host whose
hub connection never came up. When a host unmounts (MainLayout.vue rebuilds its keep-alive
wrapper on a project change; a plain route change only deactivates the page) both run: the
composable posts its removals and then stops its own connection, whose sweep finds nothing left to
evict. A key registered through neither path leaks for the life of the process.
Notice
- before current key modified, the previous key should be called this.cleanupKey.
- A twin key should be made from the outside key to keep the lifecycle maintained.
See Also
- Object Store (IndexService) — the process-wide store these keys live in, and what removing one does and does not do