@@ -54,7 +54,7 @@ const COMPLETE_FILENAME: &str = ".complete";
5454/// simultaneously. It keeps any [`PathBuf`] handed out by [`Cache::get`] valid for the
5555/// life of the cache.
5656///
57- /// - **Exclusive** is only attempted once, at [`Cache::new `], to run [`Cache::clean`].
57+ /// - **Exclusive** is only attempted once, at [`Cache::open `], to run [`Cache::clean`].
5858/// It is skipped if another session already holds the shared lock, in which case we
5959/// just try again next time.
6060///
@@ -81,13 +81,13 @@ impl Cache {
8181 /// Runs a best-effort [`Cache::clean`] under the exclusive root lock (skipped if
8282 /// another session holds the shared lock), then holds the shared root lock for the
8383 /// life of the returned `Cache` so handed-out paths stay valid.
84- pub fn new ( root : & str , capacity : usize ) -> anyhow:: Result < Self > {
85- Self :: new_in ( cache_dir ( ) ?. join ( root) , capacity)
84+ pub fn open ( root : & str , capacity : usize ) -> anyhow:: Result < Self > {
85+ Self :: open_in ( cache_dir ( ) ?. join ( root) , capacity)
8686 }
8787
88- /// Like [`Cache::new `], but rooted at an explicit `root` rather than a subfolder of
88+ /// Like [`Cache::open `], but rooted at an explicit `root` rather than a subfolder of
8989 /// the shared cache directory. Only useful for testing against a temp directory.
90- pub fn new_in ( root : PathBuf , capacity : usize ) -> anyhow:: Result < Self > {
90+ pub fn open_in ( root : PathBuf , capacity : usize ) -> anyhow:: Result < Self > {
9191 let root = Filesystem :: new ( root) ;
9292 root. create_dir ( ) ?;
9393
@@ -293,7 +293,7 @@ mod tests {
293293 /// alive for the test.
294294 fn new ( capacity : usize ) -> ( TempDir , Cache ) {
295295 let dir = TempDir :: new ( ) . unwrap ( ) ;
296- let cache = Cache :: new_in ( dir. path ( ) . join ( "subfolder" ) , capacity) . unwrap ( ) ;
296+ let cache = Cache :: open_in ( dir. path ( ) . join ( "subfolder" ) , capacity) . unwrap ( ) ;
297297 ( dir, cache)
298298 }
299299
@@ -357,15 +357,15 @@ mod tests {
357357
358358 // Populate one good entry, then forge a crashed partial (no `.complete`).
359359 {
360- let cache = Cache :: new_in ( root. clone ( ) , 10 ) . unwrap ( ) ;
360+ let cache = Cache :: open_in ( root. clone ( ) , 10 ) . unwrap ( ) ;
361361 cache. insert ( "good" , write_file ( "ok" ) ) . unwrap ( ) ;
362362 }
363363 let partial = root. join ( "partial" ) ;
364364 std:: fs:: create_dir ( & partial) . unwrap ( ) ;
365365 std:: fs:: write ( partial. join ( "content.txt" ) , "junk" ) . unwrap ( ) ;
366366
367367 // Reopening runs `clean`, which removes the partial but keeps the good entry.
368- let cache = Cache :: new_in ( root, 10 ) . unwrap ( ) ;
368+ let cache = Cache :: open_in ( root, 10 ) . unwrap ( ) ;
369369 assert ! ( !partial. exists( ) ) ;
370370 assert ! ( cache. get( "good" ) . is_some( ) ) ;
371371 }
@@ -376,7 +376,7 @@ mod tests {
376376 let root = dir. path ( ) . join ( "subfolder" ) ;
377377
378378 {
379- let cache = Cache :: new_in ( root. clone ( ) , 10 ) . unwrap ( ) ;
379+ let cache = Cache :: open_in ( root. clone ( ) , 10 ) . unwrap ( ) ;
380380 cache. insert ( "good" , write_file ( "ok" ) ) . unwrap ( ) ;
381381 }
382382 // A stray file in the cache root that doesn't belong to any entry.
@@ -385,7 +385,7 @@ mod tests {
385385
386386 // Reopening runs `clean`, which removes the stray file but keeps our root
387387 // `.lock` and the good entry.
388- let cache = Cache :: new_in ( root. clone ( ) , 10 ) . unwrap ( ) ;
388+ let cache = Cache :: open_in ( root. clone ( ) , 10 ) . unwrap ( ) ;
389389 assert ! ( !stray. exists( ) ) ;
390390 assert ! ( root. join( ".lock" ) . exists( ) ) ;
391391 assert ! ( cache. get( "good" ) . is_some( ) ) ;
@@ -400,15 +400,15 @@ mod tests {
400400 // Insert four entries under a capacity that won't evict, then stamp their
401401 // access times so the ordering is deterministic.
402402 {
403- let cache = Cache :: new_in ( root. clone ( ) , 10 ) . unwrap ( ) ;
403+ let cache = Cache :: open_in ( root. clone ( ) , 10 ) . unwrap ( ) ;
404404 for ( index, key) in [ "oldest" , "older" , "newer" , "newest" ] . iter ( ) . enumerate ( ) {
405405 let entry = cache. insert ( key, write_file ( key) ) . unwrap ( ) . unwrap ( ) ;
406406 set_accessed ( & entry, now + Duration :: from_secs ( index as u64 ) ) ;
407407 }
408408 }
409409
410410 // Reopening with capacity 2 evicts the two least-recently-accessed.
411- let cache = Cache :: new_in ( root, 2 ) . unwrap ( ) ;
411+ let cache = Cache :: open_in ( root, 2 ) . unwrap ( ) ;
412412 assert_eq ! ( cache. get( "oldest" ) , None ) ;
413413 assert_eq ! ( cache. get( "older" ) , None ) ;
414414 assert ! ( cache. get( "newer" ) . is_some( ) ) ;
0 commit comments