memoize to disk - python - persistent memoization

前端 未结 9 898
再見小時候
再見小時候 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:18

    The Artemis library has a module for this. (you'll need to pip install artemis-ml)

    You decorate your function:

    from artemis.fileman.disk_memoize import memoize_to_disk
    
    @memoize_to_disk
    def fcn(a, b, c = None):
        results = ...
        return results
    

    Internally, it makes a hash out of input arguments and saves memo-files by this hash.

提交回复
热议问题