Show HN: File-based cache for slow Python functions
docs.sweep.dev
Show HN: File-based cache for slow Python functions
1–10 of 60 posts
Re: Show HN: File-based cache for slow Python functions
#2Re: Show HN: File-based cache for slow Python functions
#3Does this also take care of the thundering heard problem? That was one of the cases where lru_cache really blows
Re: Show HN: File-based cache for slow Python functions
#4I like the simplicity. I definitely get the payoff for standalone Python scripts, where once the script errors out the memory is cleared. But do you see a similar payoff for Jupyter notebooks (or similar)?
I think it could help if you forget to save the output of a function within a single cell like this:
1. print(f(x)) # -> check what happened 2. out = f(x) # -> turns out we want to save this, so we have to wait again
Re: Show HN: File-based cache for slow Python functions
#5This is a pretty good implementation. I like the simplicity of it, reminds me of SQLite backed storage decorators we used to have, where the data was persisted to a DB instead of the file system (altho thats just a different storage engine) Does this also take care of the thundering heard problem? That was one of the cases where lru_cache really blows
Sometimes caching can actually be slower for certain functions, because just performing that operation is faster than pickle.load/pickle.dump.
Re: Show HN: File-based cache for slow Python functions
#6Re: Show HN: File-based cache for slow Python functions
#7I have extensively used https://pypi.org/project/diskcache/ . Is there a reason you decided to make an in house solution?
Re: Show HN: File-based cache for slow Python functions
#8I have extensively used https://pypi.org/project/diskcache/ . Is there a reason you decided to make an in house solution?
I found DiskCache sometime last year, it's amazing. Very simple to set up and works great as a cache for so many different things.
Re: Show HN: File-based cache for slow Python functions
#9My local file cache Python decorator also allows the decorator to define the hash manually, either by the decorator’s parameter function call that plucks a value from the cached function params, or by calling a global function from anywhere with any arbitrary value.
What’s cool about caching results locally to files during development is the ease of invalidating caches — just delete the file named after the function and key you want.
Re: Show HN: File-based cache for slow Python functions
#10I have extensively used https://pypi.org/project/diskcache/ . Is there a reason you decided to make an in house solution?