RFC: Portable Cache #12218
jerrykingxyz
started this conversation in
RFC
RFC: Portable Cache
#12218
Replies: 1 comment
-
|
The RFC currently only lists a few data structures that need to be processed; more data structures will be added to the RFC during implementation. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Feature Name: Design Portable Cache
Start Date: 2025/11/14
Summary
Based on Persistent Cache, implement Portable Cache, where the generated cache content supports use within the same project across platforms and paths.
Context
Implementing Portable Cache requires making the content generated by Persistent Cache platform-independent, enabling different platforms to share the same cache simultaneously. A typical use case is in CI, where Windows, Linux, and macOS can use the same cache for acceleration without generating three separate copies.
Persistent Cache Architecture RFC: #8458
Detailed design
Test
The function of the Portable Cache itself is easy to understand. It primarily affects the content of persistent cache, and we need to add two new test types to ensure its functionality.
Functional Test
The purpose of functional test is mainly to ensure that the basic functions of the portable cache operate normally when it is enabled, with a greater emphasis on the same test item, the same operating system, and different project paths.
Due to the functional requirement for directory change, it is necessary to newly introduce
NEXT_MOVE_DIR_STARTpre-set utility function for CacheCase.Cache Content Test
Functional testing cannot detect some behavioral anomalies in different operating systems, such as
to_ne_bytes, etc.Cache content testing focuses more on the same test item, different operating systems, and different project paths, achieving the testing objective by comparing the contents of
.cachefiles generated by different operating systems.Since directly comparing the contents of the
.cachedirectory has issues such as uncertain content order, including time fields, etc., we need to customize the comparison logic. The adopted solution is to add a new crate (rspack_storage_compare) to compare the contents of the.cache directory by writing Rust code.To obtain the
.cachefiles generated by different operating systems, we need to upload the.cachefiles of cacheCase when the linux and windows tests are completed, and then separately start a task to run the crate for comparison.Code Implementation
The Portable Cache feature requires an additional switch to be added to the Persistent Cache configuration for control, with the default value set to false.
Portable Cache is built on top of Persistent Cache, and only requires additional processing during the Serialization/Deserialization of MemoryCache to convert platform-specific data (e.g., convert absolute paths to relative paths).
Portable cache implementation is relatively simple, with mainly three changes
config.contextandcache.portablerelated information, which is convenient for corresponding structures to customize the conversion process.The value of
cache.portableis involved in the calculation of the cache directory, and a new cache should be generated whencache.portableis modified.Some data structures need to implement Serialize / Deserialize separately to ensure the portability of the output. Below are some of the relevant data structures.
ArcPath / PathBuf
For Portable cache, absolute paths must not exist, so we can customize the Serialization/Deserialization logic to convert them into relative paths for storage.
User project may use resources outside the project (outside config.context), and the portable cache also needs to convert them into relative directories. According to the current code, if these files do not exist in the new environment, it will trigger the reconstruction of the relevant module, and theoretically, there will be no correctness issues.
ModuleIdentifier
There are also some absolute paths in ModuleIdentifier, which need to be split and replaced during the Serialization/Deserialization process
SourceCode
Absolute paths may appear in SourceCode, which may be deliberately set by the user or injected during loader execution. We will discuss these in two scenarios.
For this situation, we don't need to replace the path within it; we just need to ensure that the path in the corresponding dependency is replaced.
No replacement is performed in this case, but efforts should be made to avoid cross-platform issues caused by the loader introducing this situation. For rspack internal plugins, it is necessary to ensure that the output does not contain absolute paths, while third-party plugins are constrained by specifications.
Beta Was this translation helpful? Give feedback.
All reactions