chore: add caching for engines to improve load time #4481
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Describe Your Changes
Currently, the app waits for the cortex.cpp server to load before displaying the current model and engines, which is not user-friendly.
This PR introduces a SWR storage cache provider to eliminate any delays users experience when opening the app, especially after engine persistence.
Changes
This pull request includes several important changes to the
web/containers
directory, focusing on improving the caching mechanism and simplifying the codebase. The most significant changes include the addition of a newSWRConfigProvider
component, updates to theProviders
component to use the new provider, and a minor simplification in theTableActiveModel
component.Improvements to caching mechanism:
web/containers/Providers/SWRConfigProvider.tsx
: Added a newSWRConfigProvider
component to manage caching usinglocalStorage
. This component initializes the cache fromlocalStorage
and saves it back before unloading.web/containers/Providers/index.tsx
: ImportedSWRConfigProvider
and wrapped the existing providers with it to enable the new caching mechanism. [1] [2]Codebase simplification:
web/containers/Layout/BottomPanel/SystemMonitor/TableActiveModel/index.tsx
: Simplified the conditional rendering logic by removing the unnecessaryengines
check.Additional imports:
web/containers/Providers/index.tsx
: Added import forSWRConfig
to support the new caching mechanism.