File tree Expand file tree Collapse file tree 3 files changed +17
-13
lines changed
dynamic_expressions/cache Expand file tree Collapse file tree 3 files changed +17
-13
lines changed Original file line number Diff line number Diff line change @@ -43,14 +43,16 @@ async def on_visit(
4343 key = policy .key (node , provided_context )
4444 serializer = policy .serializer or self .default_serializer
4545 cached_value = await self .get_cache (key )
46+ deserialized_value : object | None = None
4647 if cached_value is not None :
47- execution_context .cache [node ] = serializer .deserialize (cached_value )
48+ deserialized_value = serializer .deserialize (cached_value )
49+ execution_context .cache [node ] = deserialized_value
4850
4951 yield
5052
5153 if (
5254 node in execution_context .cache
53- and cached_value != execution_context .cache [node ]
55+ and deserialized_value != execution_context .cache [node ]
5456 ):
5557 await self .set_cache (
5658 key = key ,
Original file line number Diff line number Diff line change 11from collections .abc import Sequence
2- from typing import TYPE_CHECKING , Any
3-
4- from redis .asyncio import Redis
2+ from datetime import timedelta
3+ from typing import Any , Protocol
54
65from dynamic_expressions .cache .base import CacheExtension , CachePolicy
76from dynamic_expressions .serialization import Serializer
87from dynamic_expressions .types import EmptyContext
98
10- if TYPE_CHECKING :
11- RedisClient = Redis [bytes ]
12- else :
13- RedisClient = Redis
9+
10+ class RedisClient (Protocol ):
11+ async def get (self , name : str ) -> bytes | None : ...
12+ async def set (
13+ self ,
14+ name : str ,
15+ value : bytes ,
16+ ex : timedelta | int ,
17+ ) -> None : ...
1418
1519
16- class RedisCacheExtension [
17- Context : EmptyContext ,
18- ](CacheExtension [Context ]):
20+ class RedisCacheExtension [Context : EmptyContext ](CacheExtension [Context ]):
1921 def __init__ (
2022 self ,
2123 client : RedisClient ,
Original file line number Diff line number Diff line change @@ -62,7 +62,7 @@ exclude_lines = [
6262
6363[tool .deptry ]
6464[tool .deptry .per_rule_ignores ]
65- DEP002 = []
65+ DEP002 = [" redis " ]
6666
6767[tool .mypy ]
6868plugins = [
You can’t perform that action at this time.
0 commit comments