https://github.com/stanfordnlp/dspy/blob/main/dsp/modules/ca...
Show HN: File-based cache for slow Python functions
51–60 of 60 posts
Re: Show HN: File-based cache for slow Python functions
#52Earlier quoted context omitted.
Using md5 for this seems like an odd choice. Sha1 is a better choice even for non-cryptographic use cases, it's quite a bit faster than md5. Even better would be something like xxhash! According to a quick bash script I wrote to benchmark the popular hash functions, md5 comes out last compared to sha1, sha256, sha512, and blake2, and by a decent margin! A good rule of thumb is to never use md5 at all. Not even for no…
That sounds great, I'm going to see how Sweep does on this issue: https://github.com/sweepai/sweep/issues/3333
Re: Show HN: File-based cache for slow Python functions
#53Re: Show HN: File-based cache for slow Python functions
#54What's the difference to using joblibs Memory class similar to this implementation: https://github.com/stanfordnlp/dspy/blob/main/dsp/modules/ca...
memory = joblib.memory.Memory(...)
@memory.cache
def slow_func(...):
...Re: Show HN: File-based cache for slow Python functions
#55What's the difference to using joblibs Memory class similar to this implementation: https://github.com/stanfordnlp/dspy/blob/main/dsp/modules/ca...
I was going to mention this as well. It's fairly similar: memory = joblib.memory.Memory(...) @memory.cache def slow_func(...): ...
""" Caching Libraries
joblib.Memory provides caching functions and works by explicitly saving the inputs and outputs to files. It is designed to work with non-hashable and potentially large input and output data types such as numpy arrays.
"""
From https://pypi.org/project/diskcache/Re: Show HN: File-based cache for slow Python functions
#56Earlier quoted context omitted.
I was going to mention this as well. It's fairly similar: memory = joblib.memory.Memory(...) @memory.cache def slow_func(...): ...
The diskcache docs state: """ Caching Libraries joblib.Memory provides caching functions and works by explicitly saving the inputs and outputs to files. It is designed to work with non-hashable and potentially large input and output data types such as numpy arrays. """ From https://pypi.org/project/diskcache/
Re: Show HN: File-based cache for slow Python functions
#57Recently, I experimented with various techniques to cache some JSON responses from FastAPI, using Python decorators for both in-memory and disk caching on a single machine. After benchmarking the performance, I found the results somewhat disappointing (500 req/s vs 5k req/s). While caching did lead to a tenfold improvement in speed compared to no caching, I believe the primary bottleneck was Python's inherent perform…
Re: Show HN: File-based cache for slow Python functions
#58The main difference is that it stores the state of an object, not a function.
If your data is JSON serializable then it could be a cool way to save and resume application state.
Re: Show HN: File-based cache for slow Python functions
#59Earlier quoted context omitted.
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.
What are you using it for? A disk based cache seems almost contradictory for my use cases, I would love to hear yours. Anything that I would store on disk, even as a cache, I can generally put in SQLite.
I used DiskCache to cache responses for ~15 minutes so I wasn't sending live requests every time I tested the app.
I'm not building anything "cloud scale," most things I run are off my local machine. Having a convenient, fast local cache that's simple to use (DiskCache) has so many uses, it's hard to think of them all! I might use a cache with no expiration to store some configs, or to store a serialized object for later retrieval. I might use it as an in-memory object cache while the program loads, so I don't have to spin up a Redis server.