@@ -209,9 +209,6 @@ class LRUCache(Generic[T, U]):
209
209
CacheInfo(hits=194, misses=99, capacity=100, current size=99)
210
210
"""
211
211
212
- # class variable to map the decorator functions to their respective instance
213
- decorator_function_to_instance_map : dict [Callable [[T ], U ], LRUCache [T , U ]] = {} # noqa: RUF012
214
-
215
212
def __init__ (self , capacity : int ):
216
213
self .list : DoubleLinkedList [T , U ] = DoubleLinkedList ()
217
214
self .capacity = capacity
@@ -308,18 +305,21 @@ def decorator(
308
305
"""
309
306
310
307
def cache_decorator_inner (func : Callable [[T ], U ]) -> Callable [..., U ]:
308
+ # variable to map the decorator functions to their respective instance
309
+ decorator_function_to_instance_map : dict [Callable [[T ], U ], LRUCache [T , U ]] = {}
310
+
311
311
def cache_decorator_wrapper (* args : T ) -> U :
312
- if func not in cls . decorator_function_to_instance_map :
313
- cls . decorator_function_to_instance_map [func ] = LRUCache (size )
312
+ if func not in decorator_function_to_instance_map :
313
+ decorator_function_to_instance_map [func ] = LRUCache (size )
314
314
315
- result = cls . decorator_function_to_instance_map [func ].get (args [0 ])
315
+ result = decorator_function_to_instance_map [func ].get (args [0 ])
316
316
if result is None :
317
317
result = func (* args )
318
- cls . decorator_function_to_instance_map [func ].put (args [0 ], result )
318
+ decorator_function_to_instance_map [func ].put (args [0 ], result )
319
319
return result
320
320
321
321
def cache_info () -> LRUCache [T , U ]:
322
- return cls . decorator_function_to_instance_map [func ]
322
+ return decorator_function_to_instance_map [func ]
323
323
324
324
setattr (cache_decorator_wrapper , "cache_info" , cache_info ) # noqa: B010
325
325
0 commit comments