@@ -99,7 +99,7 @@ def invalidate(self):
99
99
self .callbacks .clear ()
100
100
101
101
102
- class Cache (Generic [KT , VT ]):
102
+ class DeferredCache (Generic [KT , VT ]):
103
103
"""Wraps an LruCache, adding support for Deferred results.
104
104
105
105
It expects that each entry added with set() will be a Deferred; likewise get()
@@ -225,7 +225,10 @@ def get(
225
225
return default
226
226
227
227
def set (
228
- self , key : KT , value : defer .Deferred , callback : Optional [Callable [[], None ]] = None
228
+ self ,
229
+ key : KT ,
230
+ value : defer .Deferred ,
231
+ callback : Optional [Callable [[], None ]] = None ,
229
232
) -> ObservableDeferred :
230
233
if not isinstance (value , defer .Deferred ):
231
234
raise TypeError ("not a Deferred" )
@@ -427,13 +430,13 @@ def __init__(
427
430
self .iterable = iterable
428
431
429
432
def __get__ (self , obj , owner ):
430
- cache = Cache (
433
+ cache = DeferredCache (
431
434
name = self .orig .__name__ ,
432
435
max_entries = self .max_entries ,
433
436
keylen = self .num_args ,
434
437
tree = self .tree ,
435
438
iterable = self .iterable ,
436
- ) # type: Cache [Tuple, Any]
439
+ ) # type: DeferredCache [Tuple, Any]
437
440
438
441
def get_cache_key_gen (args , kwargs ):
439
442
"""Given some args/kwargs return a generator that resolves into
@@ -677,9 +680,9 @@ class _CacheContext:
677
680
678
681
_cache_context_objects = (
679
682
WeakValueDictionary ()
680
- ) # type: WeakValueDictionary[Tuple[Cache , CacheKey], _CacheContext]
683
+ ) # type: WeakValueDictionary[Tuple[DeferredCache , CacheKey], _CacheContext]
681
684
682
- def __init__ (self , cache , cache_key ): # type: (Cache , CacheKey) -> None
685
+ def __init__ (self , cache , cache_key ): # type: (DeferredCache , CacheKey) -> None
683
686
self ._cache = cache
684
687
self ._cache_key = cache_key
685
688
@@ -688,7 +691,9 @@ def invalidate(self): # type: () -> None
688
691
self ._cache .invalidate (self ._cache_key )
689
692
690
693
@classmethod
691
- def get_instance (cls , cache , cache_key ): # type: (Cache, CacheKey) -> _CacheContext
694
+ def get_instance (
695
+ cls , cache , cache_key
696
+ ): # type: (DeferredCache, CacheKey) -> _CacheContext
692
697
"""Returns an instance constructed with the given arguments.
693
698
694
699
A new instance is only created if none already exists.
0 commit comments