File tree Expand file tree Collapse file tree 2 files changed +4
-7
lines changed
src/stac_auth_proxy/utils Expand file tree Collapse file tree 2 files changed +4
-7
lines changed Original file line number Diff line number Diff line change @@ -15,9 +15,6 @@ class MemoryCache:
15
15
cache : dict [tuple [Any ], tuple [Any , float ]] = field (default_factory = dict )
16
16
_last_pruned : float = field (default_factory = time )
17
17
18
- class Expired (Exception ):
19
- """Exception raised when a cache entry has expired."""
20
-
21
18
def __getitem__ (self , key : Any ) -> Any :
22
19
"""Get a value from the cache if it is not expired."""
23
20
if key not in self .cache :
@@ -30,7 +27,7 @@ def __getitem__(self, key: Any) -> Any:
30
27
msg = f"{ self ._key_str (key )} in cache, but expired."
31
28
del self .cache [key ]
32
29
logger .debug (msg )
33
- raise self . Expired (f"{ key } expired" )
30
+ raise KeyError (f"{ key } expired" )
34
31
35
32
logger .debug (f"{ self ._key_str (key )} in cache, returning cached result." )
36
33
return result
@@ -45,14 +42,14 @@ def __contains__(self, key: Any) -> bool:
45
42
try :
46
43
self [key ]
47
44
return True
48
- except ( KeyError , self . Expired ) :
45
+ except KeyError :
49
46
return False
50
47
51
48
def get (self , key : Any ) -> Any :
52
49
"""Get a value from the cache."""
53
50
try :
54
51
return self [key ]
55
- except ( KeyError , self . Expired ) :
52
+ except KeyError :
56
53
return None
57
54
58
55
def _prune (self ):
Original file line number Diff line number Diff line change @@ -43,7 +43,7 @@ def test_memory_cache_expiration():
43
43
mock_time .return_value = 1006.0 # 6 seconds later
44
44
45
45
# Test expired key
46
- with pytest .raises (MemoryCache . Expired ):
46
+ with pytest .raises (KeyError ):
47
47
cache [key ]
48
48
49
49
# Test contains after expiration
You can’t perform that action at this time.
0 commit comments