memoize to disk - python - persistent memoization

前端 未结 9 843
再見小時候
再見小時候 2020-12-24 05:34

Is there a way to memoize the output of a function to disk?

I have a function

def getHtmlOfUrl(url):
    ... # expensive computation
<
9条回答
  •  一生所求
    2020-12-24 06:19

    There is also diskcache.

    from diskcache import Cache
    
    cache = Cache("cachedir")
    
    @cache.memoize()
    def f(x, y):
        print('Running f({}, {})'.format(x, y))
        return x, y
    

提交回复
热议问题