|
53 | 53 | DEFAULT_BLACKLIST, |
54 | 54 | DEFAULT_EVICTION_POLICY, |
55 | 55 | DEFAULT_WHITELIST, |
| 56 | + AbstractCache, |
56 | 57 | _LocalCache, |
57 | 58 | ) |
58 | 59 | from .._parsers import ( |
@@ -156,11 +157,11 @@ def __init__( |
156 | 157 | encoder_class: Type[Encoder] = Encoder, |
157 | 158 | credential_provider: Optional[CredentialProvider] = None, |
158 | 159 | protocol: Optional[int] = 2, |
159 | | - cache_enable: bool = False, |
160 | | - client_cache: Optional[_LocalCache] = None, |
161 | | - cache_max_size: int = 100, |
| 160 | + cache_enabled: bool = False, |
| 161 | + client_cache: Optional[AbstractCache] = None, |
| 162 | + cache_max_size: int = 10000, |
162 | 163 | cache_ttl: int = 0, |
163 | | - cache_eviction_policy: str = DEFAULT_EVICTION_POLICY, |
| 164 | + cache_policy: str = DEFAULT_EVICTION_POLICY, |
164 | 165 | cache_blacklist: List[str] = DEFAULT_BLACKLIST, |
165 | 166 | cache_whitelist: List[str] = DEFAULT_WHITELIST, |
166 | 167 | ): |
@@ -220,8 +221,8 @@ def __init__( |
220 | 221 | if p < 2 or p > 3: |
221 | 222 | raise ConnectionError("protocol must be either 2 or 3") |
222 | 223 | self.protocol = protocol |
223 | | - if cache_enable: |
224 | | - _cache = _LocalCache(cache_max_size, cache_ttl, cache_eviction_policy) |
| 224 | + if cache_enabled: |
| 225 | + _cache = _LocalCache(cache_max_size, cache_ttl, cache_policy) |
225 | 226 | else: |
226 | 227 | _cache = None |
227 | 228 | self.client_cache = client_cache if client_cache is not None else _cache |
@@ -698,7 +699,7 @@ def _cache_invalidation_process( |
698 | 699 | self.client_cache.flush() |
699 | 700 | else: |
700 | 701 | for key in data[1]: |
701 | | - self.client_cache.invalidate(str_if_bytes(key)) |
| 702 | + self.client_cache.invalidate_key(str_if_bytes(key)) |
702 | 703 |
|
703 | 704 | async def _get_from_local_cache(self, command: str): |
704 | 705 | """ |
@@ -728,15 +729,6 @@ def _add_to_local_cache( |
728 | 729 | ): |
729 | 730 | self.client_cache.set(command, response, keys) |
730 | 731 |
|
731 | | - def delete_from_local_cache(self, command: str): |
732 | | - """ |
733 | | - Delete the command from the local cache |
734 | | - """ |
735 | | - try: |
736 | | - self.client_cache.delete(command) |
737 | | - except AttributeError: |
738 | | - pass |
739 | | - |
740 | 732 |
|
741 | 733 | class Connection(AbstractConnection): |
742 | 734 | "Manages TCP communication to and from a Redis server" |
@@ -1240,6 +1232,36 @@ def set_retry(self, retry: "Retry") -> None: |
1240 | 1232 | for conn in self._in_use_connections: |
1241 | 1233 | conn.retry = retry |
1242 | 1234 |
|
| 1235 | + def flush_cache(self): |
| 1236 | + connections = chain(self._available_connections, self._in_use_connections) |
| 1237 | + |
| 1238 | + for connection in connections: |
| 1239 | + try: |
| 1240 | + connection.client_cache.flush() |
| 1241 | + except AttributeError: |
| 1242 | + # cache is not enabled |
| 1243 | + pass |
| 1244 | + |
| 1245 | + def delete_command_from_cache(self, command: str): |
| 1246 | + connections = chain(self._available_connections, self._in_use_connections) |
| 1247 | + |
| 1248 | + for connection in connections: |
| 1249 | + try: |
| 1250 | + connection.client_cache.delete_command(command) |
| 1251 | + except AttributeError: |
| 1252 | + # cache is not enabled |
| 1253 | + pass |
| 1254 | + |
| 1255 | + def invalidate_key_from_cache(self, key: str): |
| 1256 | + connections = chain(self._available_connections, self._in_use_connections) |
| 1257 | + |
| 1258 | + for connection in connections: |
| 1259 | + try: |
| 1260 | + connection.client_cache.invalidate_key(key) |
| 1261 | + except AttributeError: |
| 1262 | + # cache is not enabled |
| 1263 | + pass |
| 1264 | + |
1243 | 1265 |
|
1244 | 1266 | class BlockingConnectionPool(ConnectionPool): |
1245 | 1267 | """ |
|
0 commit comments