@@ -53,25 +53,35 @@ def save_cookies(self):
53
53
with COOKIESFILE .open ('wb' ) as file :
54
54
pickle .dump (self .session .cookies , file )
55
55
56
- def invalidate_cache (self , url : str ):
56
+ def invalidate_cache (self , url : str , allparams : bool = False ):
57
57
"""Invalidate cache for a given URL."""
58
58
with cache_lock :
59
- for file in self ._get_cache_file_candidates (url ):
60
- file .unlink (missing_ok = True )
59
+ if allparams :
60
+ prefix = self ._get_cache_file_prefix (url )
61
+ for file in prefix .parent .glob (f"{ prefix .name } *" ):
62
+ file .unlink ()
63
+ else :
64
+ for file in self ._get_cache_file_candidates (url ):
65
+ file .unlink (missing_ok = True )
61
66
62
- def _get_cache_file_candidates (self , url : str ) -> list [ pathlib .Path ] :
67
+ def _get_cache_file_prefix (self , url : str ) -> pathlib .Path :
63
68
filestem = url .split ('://' , 1 )[1 ].replace ('/' , '_' ).replace (':' , '_' )
64
69
65
70
if len (filestem ) > 100 :
66
71
hashname = hashlib .sha256 (filestem .encode (), usedforsecurity = False )
67
72
filestem = hashname .hexdigest ()
68
73
74
+ return utils .CACHEDIR / filestem
75
+
76
+ def _get_cache_file_candidates (self , url : str ) -> list [pathlib .Path ]:
77
+ prefix = self ._get_cache_file_prefix (url )
78
+
69
79
candidates = [
70
- utils . CACHEDIR / f" { filestem } .gz" ,
71
- utils . CACHEDIR / filestem ,
80
+ prefix . parent / f' { prefix . name } .gz' ,
81
+ prefix ,
72
82
73
83
# For compatibility with old cache files
74
- utils . CACHEDIR / f" { filestem } .json" ,
84
+ prefix . parent / f' { prefix . name } .json' ,
75
85
]
76
86
77
87
return candidates
0 commit comments