Cache the results of a function.
Simple use
Decorate the function with @cache(cachedir, **kwargs). For example,
@cache()
def is_prime(number):
for n in range(2, number):
if number % n == 0:
return False
return True
Fancier uses
Non-default directory
If you pass no arguments to cache, as in the example above, the cache will be stored in a directory named after the function. To set a different directory, pass it as an argument.
@cache('~/.primes')
def is_prime(number):
for n in range(2, number):
if number % n == 0:
return False
return True
I recommend storing your caches in dotted directories under your home directory, as you see above.
Configuration
The kwargs get passed to the pickle_warehouse.Warehouse, so you can do fun things like changing the serialization function.
@cache('~/.http', serializer = pickle_warehouse.serializers.identity)
def get(url):
return requests.get(url).text
Read more about the keyword arguments on the pickle-warehouse page.
Non-identifying arguments
If you want to pass an argument but not use it as an identifier, pass a non-keyword argument; those get passed along to the function but don’t form the identifier. For example,
@cache('~/.http')
def get(url, auth = None):
return requests.get(url, auth = auth)
get('http://this.website.com', auth = ('username', 'password')
Refreshing the cache
I find that I sometimes want to refresh the cache for a particular file, only. This is usually because an error occurred and I have fixed the error or because I am downloading files from a website that doesn’t work very well.
It would be nice to have a convenient way of refreshing these files. Until then, I suggest that you log the arguments to the function call that yields the cached error and then delete the corresponding file.
Metadata
Release files for picklecache 0.0.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| picklecache-0.0.5.tar.gz | 2.0 kB | Without provenance | Details for picklecache-0.0.5.tar.gz |
Release files / picklecache-0.0.5.tar.gz
| Download URL | picklecache-0.0.5.tar.gz |
|---|---|
| Size | 2.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
23e94d2cf86c05b1c4404e89aecabe2bd8ee1c43f221dcd8dec7456b5aa75bd4
|
|
BLAKE2b-256 checksum How to use checksums |
d352e3b28339f1bdac1af77c4aa2275c9f5b5d0a6303f05acc0f1693596c68c7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for picklecache 0.0.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.