@@ -27,17 +27,17 @@ class Cache:
2727 def __init__ (self , cache_path : Path = None ) -> None :
2828 """Initialize the class."""
2929 self .cache_path : Path = cache_path
30- self .cache : shelve .Shelf [Any ] = self . open ( protocol = 5 )
30+ self .cache : shelve .Shelf [Any ] = None
3131
3232 def __repr__ (self ) -> str :
3333 return f'{ self .__class__ .__qualname__ } (cache_path="{ self .cache_path } ")'
3434
3535 def __str__ (self ) -> str :
3636 return f"{ self .__class__ .__qualname__ } : { self .cache_path } "
3737
38- def open (self , protocol : int = 5 ) -> shelve . Shelf [ Any ] :
38+ def open (self , protocol : int = 5 ) -> None :
3939 """Open the cache file."""
40- return shelve .open (self .cache_path , protocol = protocol )
40+ self . cache = shelve .open (self .cache_path , protocol = protocol )
4141
4242 def close (self ) -> None :
4343 """Close the cache file."""
@@ -63,8 +63,8 @@ def initialize(self, clear: bool, index: "FileIndex") -> None:
6363 def clear (self ) -> None :
6464 """Clear the cache."""
6565 self .close ()
66- self .cache_path .unlink ()
67- self .cache = self . open (protocol = 5 )
66+ self .cache_path .unlink (missing_ok = True )
67+ self .open ()
6868
6969 def clear_deleted_files (self , index : "FileIndex" ) -> None :
7070 """Clear the deleted files from the cache."""
0 commit comments