@@ -43,18 +43,28 @@ pub const CURRENT_QUERY_CACHE_VERSION: &str = "v1";
43
43
// .cache.json
44
44
#[ derive( Default , Clone , serde:: Deserialize , serde:: Serialize , Debug , Hash , Eq , PartialEq ) ]
45
45
pub struct CacheMetadata {
46
- query : String ,
46
+ pub query : String ,
47
47
pub start_time : String ,
48
48
pub end_time : String ,
49
49
}
50
50
51
+ impl CacheMetadata {
52
+ pub const fn new ( query : String , start_time : String , end_time : String ) -> Self {
53
+ Self {
54
+ query,
55
+ start_time,
56
+ end_time,
57
+ }
58
+ }
59
+ }
60
+
51
61
#[ derive( Debug , serde:: Deserialize , serde:: Serialize ) ]
52
62
pub struct QueryCache {
53
63
version : String ,
54
64
current_size : u64 ,
55
65
56
66
/// Mapping between storage path and cache path.
57
- files : Cache < String , PathBuf > ,
67
+ files : Cache < CacheMetadata , PathBuf > ,
58
68
}
59
69
60
70
impl QueryCache {
@@ -66,7 +76,7 @@ impl QueryCache {
66
76
}
67
77
}
68
78
69
- pub fn get_file ( & mut self , key : String ) -> Option < PathBuf > {
79
+ pub fn get_file ( & mut self , key : CacheMetadata ) -> Option < PathBuf > {
70
80
self . files . get ( & key) . cloned ( )
71
81
}
72
82
@@ -245,7 +255,7 @@ impl QueryCacheManager {
245
255
pub async fn move_to_cache (
246
256
& self ,
247
257
stream : & str ,
248
- key : String ,
258
+ key : CacheMetadata ,
249
259
file_path : & Path ,
250
260
user_id : & str ,
251
261
) -> Result < ( ) , CacheError > {
@@ -309,7 +319,7 @@ impl QueryCacheManager {
309
319
arrow_writer. close ( ) . await ?;
310
320
self . move_to_cache (
311
321
table_name,
312
- format ! ( "{}-{}-{}" , start, end, query ) ,
322
+ CacheMetadata :: new ( query , start, end) ,
313
323
& parquet_path,
314
324
user_id,
315
325
)
0 commit comments