@@ -69,30 +69,7 @@ def convert_to_seconds(unit: str = None, amount: int = None) -> int:
69
69
return _amount
70
70
71
71
72
- # def get_cache(
73
- # cache_dir: str = default_cache_dir,
74
- # index: bool = True,
75
- # ) -> diskcache.core.Cache:
76
- # """Prepare and return a diskcache.Cache object."""
77
- # if not cache_dir:
78
- # raise ValueError("Missing cache directory")
79
-
80
- # if not isinstance(cache_dir, Union[str, Path]):
81
- # raise TypeError(f"cache_dir must be of type str or Path, not {type(cache_dir)}")
82
-
83
- # try:
84
- # _cache: diskcache.core.Cache = Cache(directory=cache_dir)
85
-
86
- # if index:
87
- # cache_tag_index(cache=_cache)
88
-
89
- # return _cache
90
-
91
- # except Exception as exc:
92
- # raise Exception(f"Unhandled exception creating cache. Details: {exc}")
93
-
94
-
95
- def get_cache (
72
+ def new_cache (
96
73
cache_dir : str = default_cache_dir ,
97
74
cache_conf : dict = None ,
98
75
index : bool = True ,
@@ -117,7 +94,7 @@ def get_cache(
117
94
_cache : diskcache .core .Cache = Cache (** cache_conf )
118
95
119
96
if index :
120
- cache_tag_index (cache = _cache )
97
+ manage_cache_tag_index (cache = _cache )
121
98
122
99
return _cache
123
100
@@ -140,7 +117,7 @@ def clear_cache(cache: Cache = None) -> bool:
140
117
)
141
118
142
119
143
- def check_exists (key : str = None , cache : diskcache .core .Cache = None ) -> bool :
120
+ def check_cache_key_exists (key : str = None , cache : diskcache .core .Cache = None ) -> bool :
144
121
"""Check if a key exists in a cache."""
145
122
## Key validation
146
123
validate_key (key = key )
@@ -153,7 +130,7 @@ def check_exists(key: str = None, cache: diskcache.core.Cache = None) -> bool:
153
130
return False
154
131
155
132
156
- def cache_tag_index (operation : str = "create" , cache : Cache = None ) -> None :
133
+ def manage_cache_tag_index (operation : str = "create" , cache : Cache = None ) -> None :
157
134
valid_operations : list [str ] = ["create" , "delete" ]
158
135
159
136
validate_cache (cache = cache )
@@ -222,7 +199,7 @@ def set_expire(
222
199
validate_cache (cache )
223
200
validate_expire (expire )
224
201
225
- if not check_exists (key = key , cache = cache ):
202
+ if not check_cache_key_exists (key = key , cache = cache ):
226
203
return {
227
204
"warning" : f"Cache item with key [{ key } ] does not exist in cache at { cache .directory } /"
228
205
}
@@ -242,7 +219,7 @@ def get_val(key: valid_key_types = None, cache: Cache = None, tags: list[str] =
242
219
validate_cache (cache )
243
220
validate_tags (tags )
244
221
245
- if check_exists (key = key , cache = cache ):
222
+ if check_cache_key_exists (key = key , cache = cache ):
246
223
try :
247
224
with cache as ref :
248
225
_val = ref .get (key = key )
0 commit comments