File tree Expand file tree Collapse file tree 2 files changed +5
-10
lines changed
Expand file tree Collapse file tree 2 files changed +5
-10
lines changed Original file line number Diff line number Diff line change @@ -9,24 +9,19 @@ def __init__(self):
99
1010 def is_cached (self , key : str ):
1111 """Check if key is cached."""
12- if key in self ._cache :
13- return True
14- return False
12+ return key in self ._cache
1513
1614 def store_key_value (self , key : str , value ):
1715 """Stores key-value in cache dict."""
1816 self ._cache [key ] = value
1917
2018 def retrieve_key_value (self , key : str ):
2119 """Retrieves key value from cache."""
22- if self .is_cached (key ):
23- return self ._cache .get (key )
24- return None
20+ return self ._cache .get (key )
2521
2622 def remove_key_from_cache (self , key : str ):
2723 """Deletes a key from cache."""
28- if self .is_cached (key ):
29- del self ._cache [key ]
24+ return self ._cache .pop (key , None )
3025
3126 def clear_cache (self ):
3227 """Clears the entire cache"""
Original file line number Diff line number Diff line change @@ -42,6 +42,6 @@ def test_is_cached(self):
4242
4343 def test_clear_cache (self ):
4444 """Tests that the cache attribute is cleared when the clear_cache method is called"""
45- self .cache ._cache [ "dummy" ] = "data"
45+ self .cache .store_key_value ( "key" , "value" )
4646 self .cache .clear_cache ()
47- self .assertTrue ( len ( self .cache ._cache ) == 0 )
47+ self .assertEqual ( self .cache ._cache , {} )
You can’t perform that action at this time.
0 commit comments