Skip to content

Commit 98c0f97

Browse files
committed
Improve
1 parent 02dbed5 commit 98c0f97

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

other/lfu_cache.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,6 @@ class LFUCache(Generic[T, U]):
196196
CacheInfo(hits=196, misses=100, capacity=100, current_size=100)
197197
"""
198198

199-
# class variable to map the decorator functions to their respective instance
200-
decorator_function_to_instance_map: dict[Callable[[T], U], LFUCache[T, U]] = {} # noqa: RUF012
201-
202199
def __init__(self, capacity: int):
203200
self.list: DoubleLinkedList[T, U] = DoubleLinkedList()
204201
self.capacity = capacity
@@ -291,18 +288,21 @@ def decorator(
291288
"""
292289

293290
def cache_decorator_inner(func: Callable[[T], U]) -> Callable[..., U]:
291+
# variable to map the decorator functions to their respective instance
292+
decorator_function_to_instance_map: dict[Callable[[T], U], LFUCache[T, U]] = {}
293+
294294
def cache_decorator_wrapper(*args: T) -> U:
295-
if func not in cls.decorator_function_to_instance_map:
296-
cls.decorator_function_to_instance_map[func] = LFUCache(size)
295+
if func not in decorator_function_to_instance_map:
296+
decorator_function_to_instance_map[func] = LFUCache(size)
297297

298-
result = cls.decorator_function_to_instance_map[func].get(args[0])
298+
result = decorator_function_to_instance_map[func].get(args[0])
299299
if result is None:
300300
result = func(*args)
301-
cls.decorator_function_to_instance_map[func].put(args[0], result)
301+
decorator_function_to_instance_map[func].put(args[0], result)
302302
return result
303303

304304
def cache_info() -> LFUCache[T, U]:
305-
return cls.decorator_function_to_instance_map[func]
305+
return decorator_function_to_instance_map[func]
306306

307307
setattr(cache_decorator_wrapper, "cache_info", cache_info) # noqa: B010
308308

0 commit comments

Comments
 (0)