【问题标题】:lru_cache vs cachelru_cache 与缓存
【发布时间】:2022-01-01 09:46:19
【问题描述】:

我正在使用具有时间窗实现的 Google OR Tools VRP。我想激活缓存以加快速度。我有 python 3.7.4,所以我可以使用@lru_cache。我升级到 python 3.9 并使用 @cache 是否值得?

谢谢!

【问题讨论】:

    标签: python-3.x caching or-tools


    【解决方案1】:

    看看source code,它就是这样:

    def cache(user_function, /):
        'Simple lightweight unbounded cache.  Sometimes called "memoize".'
        return lru_cache(maxsize=None)(user_function)
    

    【讨论】:

      猜你喜欢
      • 2018-01-02
      • 2017-02-21
      • 2021-12-17
      • 2021-03-28
      • 1970-01-01
      • 2020-03-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多