@@ -30,10 +30,6 @@ use crate::cache::oss::OSSCache;
3030use crate :: cache:: redis:: RedisCache ;
3131#[ cfg( feature = "s3" ) ]
3232use crate :: cache:: s3:: S3Cache ;
33- #[ cfg( feature = "webdav" ) ]
34- use crate :: cache:: webdav:: WebdavCache ;
35- use crate :: compiler:: PreprocessorCacheEntry ;
36- use crate :: config:: Config ;
3733#[ cfg( any(
3834 feature = "azure" ,
3935 feature = "gcs" ,
@@ -45,10 +41,14 @@ use crate::config::Config;
4541 feature = "oss" ,
4642 feature = "cos"
4743) ) ]
48- use crate :: config:: { self , CacheType } ;
44+ use crate :: cache:: utils:: normalize_key;
45+ #[ cfg( feature = "webdav" ) ]
46+ use crate :: cache:: webdav:: WebdavCache ;
47+ use crate :: compiler:: PreprocessorCacheEntry ;
48+ use crate :: config:: Config ;
49+ use crate :: config:: { self , CacheType , PreprocessorCacheModeConfig } ;
4950use async_trait:: async_trait;
5051
51- use serde:: { Deserialize , Serialize } ;
5252use std:: io;
5353use std:: sync:: Arc ;
5454use std:: time:: Duration ;
@@ -134,57 +134,6 @@ pub trait Storage: Send + Sync {
134134 }
135135}
136136
137- /// Configuration switches for preprocessor cache mode.
138- #[ derive( Debug , Copy , Clone , PartialEq , Eq , Serialize , Deserialize ) ]
139- #[ serde( deny_unknown_fields) ]
140- #[ serde( default ) ]
141- pub struct PreprocessorCacheModeConfig {
142- /// Whether to use preprocessor cache mode entirely
143- pub use_preprocessor_cache_mode : bool ,
144- /// If false (default), only compare header files by hashing their contents.
145- /// If true, will use size + ctime + mtime to check whether a file has changed.
146- /// See other flags below for more control over this behavior.
147- pub file_stat_matches : bool ,
148- /// If true (default), uses the ctime (file status change on UNIX,
149- /// creation time on Windows) to check that a file has/hasn't changed.
150- /// Can be useful to disable when backdating modification times
151- /// in a controlled manner.
152- pub use_ctime_for_stat : bool ,
153- /// If true, ignore `__DATE__`, `__TIME__` and `__TIMESTAMP__` being present
154- /// in the source code. Will speed up preprocessor cache mode,
155- /// but can result in false positives.
156- pub ignore_time_macros : bool ,
157- /// If true, preprocessor cache mode will not cache system headers, only
158- /// add them to the hash.
159- pub skip_system_headers : bool ,
160- /// If true (default), will add the current working directory in the hash to
161- /// distinguish two compilations from different directories.
162- pub hash_working_directory : bool ,
163- }
164-
165- impl Default for PreprocessorCacheModeConfig {
166- fn default ( ) -> Self {
167- Self {
168- use_preprocessor_cache_mode : false ,
169- file_stat_matches : false ,
170- use_ctime_for_stat : true ,
171- ignore_time_macros : false ,
172- skip_system_headers : false ,
173- hash_working_directory : true ,
174- }
175- }
176- }
177-
178- impl PreprocessorCacheModeConfig {
179- /// Return a default [`Self`], but with the cache active.
180- pub fn activated ( ) -> Self {
181- Self {
182- use_preprocessor_cache_mode : true ,
183- ..Default :: default ( )
184- }
185- }
186- }
187-
188137/// Wrapper for opendal::Operator that adds basedirs support
189138#[ cfg( any(
190139 feature = "azure" ,
@@ -332,11 +281,6 @@ impl Storage for RemoteStorage {
332281 }
333282}
334283
335- /// Normalize key `abcdef` into `a/b/c/abcdef`
336- pub ( in crate :: cache) fn normalize_key ( key : & str ) -> String {
337- format ! ( "{}/{}/{}/{}" , & key[ 0 ..1 ] , & key[ 1 ..2 ] , & key[ 2 ..3 ] , & key)
338- }
339-
340284/// Build a single cache storage from CacheType
341285/// Helper function used by storage_from_config for both single and multi-level caches
342286#[ cfg( any(
@@ -587,14 +531,6 @@ mod test {
587531 use crate :: config:: CacheModeConfig ;
588532 use fs_err as fs;
589533
590- #[ test]
591- fn test_normalize_key ( ) {
592- assert_eq ! (
593- normalize_key( "0123456789abcdef0123456789abcdef" ) ,
594- "0/1/2/0123456789abcdef0123456789abcdef"
595- ) ;
596- }
597-
598534 #[ test]
599535 fn test_read_write_mode_local ( ) {
600536 let runtime = tokio:: runtime:: Builder :: new_current_thread ( )
0 commit comments