8
8
from abc import abstractmethod
9
9
from itertools import chain
10
10
from queue import Empty , Full , LifoQueue
11
- from time import time , sleep
11
+ from time import time
12
12
from typing import Any , Callable , List , Optional , Type , Union
13
13
from urllib .parse import parse_qs , unquote , urlparse
14
14
15
15
from apscheduler .schedulers .background import BackgroundScheduler
16
- from cachetools import TTLCache , Cache , LRUCache
16
+ from cachetools import Cache , LRUCache
17
17
from cachetools .keys import hashkey
18
18
from redis .cache import CacheConfiguration , CacheFactory
19
19
@@ -773,13 +773,15 @@ def check_health(self):
773
773
self ._conn .check_health ()
774
774
775
775
def send_packed_command (self , command , check_health = True ):
776
- # TODO: Investigate if it's possible to unpack command or extract keys from packed command
776
+ # TODO: Investigate if it's possible to unpack command
777
+ # or extract keys from packed command
777
778
self ._conn .send_packed_command (command )
778
779
779
780
def send_command (self , * args , ** kwargs ):
780
781
self ._process_pending_invalidations ()
781
782
782
- # If command is write command or not allowed to cache, transfer control to the actual connection.
783
+ # If command is write command or not allowed to cache
784
+ # transfer control to the actual connection.
783
785
if not self ._conf .is_allowed_to_cache (args [0 ]):
784
786
self ._current_command_hash = None
785
787
self ._current_command_keys = None
@@ -797,14 +799,17 @@ def send_command(self, *args, **kwargs):
797
799
raise TypeError ("Cache keys must be a list." )
798
800
799
801
with self ._cache_lock :
800
- # If current command reply already cached prevent sending data over socket.
802
+ # If current command reply already cached
803
+ # prevent sending data over socket.
801
804
if self ._cache .get (self ._current_command_hash ):
802
805
return
803
806
804
- # Set temporary entry as a status to prevent race condition from another connection.
807
+ # Set temporary entry as a status to prevent
808
+ # race condition from another connection.
805
809
self ._cache [self ._current_command_hash ] = "caching-in-progress"
806
810
807
- # Send command over socket only if it's allowed read-only command that not yet cached.
811
+ # Send command over socket only if it's allowed
812
+ # read-only command that not yet cached.
808
813
self ._conn .send_command (* args , ** kwargs )
809
814
810
815
def can_read (self , timeout = 0 ):
@@ -836,7 +841,8 @@ def read_response(
836
841
elif self ._current_command_hash is None :
837
842
return response
838
843
839
- # Create separate mapping for keys or add current response to associated keys.
844
+ # Create separate mapping for keys
845
+ # or add current response to associated keys.
840
846
for key in self ._current_command_keys :
841
847
if key in self ._keys_mapping :
842
848
if self ._current_command_hash not in self ._keys_mapping [key ]:
@@ -846,7 +852,8 @@ def read_response(
846
852
847
853
cache_entry = self ._cache .get (self ._current_command_hash , None )
848
854
849
- # Cache only responses that still valid and wasn't invalidated by another connection in meantime.
855
+ # Cache only responses that still valid
856
+ # and wasn't invalidated by another connection in meantime.
850
857
if cache_entry is not None :
851
858
self ._cache [self ._current_command_hash ] = response
852
859
0 commit comments