Use functools' @lru_cache without specifying maxsize parameter

后端 未结 3 814
遇见更好的自我
遇见更好的自我 2021-01-04 03:56

The documentation for lru_cache gives the function definition:

@functools.lru_cache(maxsize=128, typed=False)

Th

3条回答
  •  再見小時候
    2021-01-04 04:16

    Think about it that way: lru_cache is a decorator factory. You call it (with or without params, but you call it) and it gives you a decorator.

    Calling the decorator factory and applying the decorator on one line is the equivalent of this:

    with_small_cache = lru_cache(max_size=5)
    
    @with_small_cache
    def function():
        ...
    

提交回复
热议问题