@@ -43,18 +43,28 @@ pub const CURRENT_QUERY_CACHE_VERSION: &str = "v1";
4343// .cache.json
4444#[ derive( Default , Clone , serde:: Deserialize , serde:: Serialize , Debug , Hash , Eq , PartialEq ) ]
4545pub struct CacheMetadata {
46- query : String ,
46+ pub query : String ,
4747 pub start_time : String ,
4848 pub end_time : String ,
4949}
5050
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+
5161#[ derive( Debug , serde:: Deserialize , serde:: Serialize ) ]
5262pub struct QueryCache {
5363 version : String ,
5464 current_size : u64 ,
5565
5666 /// Mapping between storage path and cache path.
57- files : Cache < String , PathBuf > ,
67+ files : Cache < CacheMetadata , PathBuf > ,
5868}
5969
6070impl QueryCache {
@@ -66,7 +76,7 @@ impl QueryCache {
6676 }
6777 }
6878
69- pub fn get_file ( & mut self , key : String ) -> Option < PathBuf > {
79+ pub fn get_file ( & mut self , key : CacheMetadata ) -> Option < PathBuf > {
7080 self . files . get ( & key) . cloned ( )
7181 }
7282
@@ -245,7 +255,7 @@ impl QueryCacheManager {
245255 pub async fn move_to_cache (
246256 & self ,
247257 stream : & str ,
248- key : String ,
258+ key : CacheMetadata ,
249259 file_path : & Path ,
250260 user_id : & str ,
251261 ) -> Result < ( ) , CacheError > {
@@ -309,7 +319,7 @@ impl QueryCacheManager {
309319 arrow_writer. close ( ) . await ?;
310320 self . move_to_cache (
311321 table_name,
312- format ! ( "{}-{}-{}" , start, end, query ) ,
322+ CacheMetadata :: new ( query , start, end) ,
313323 & parquet_path,
314324 user_id,
315325 )
0 commit comments