Skip to main content

A simple pickle-based caching utility.

Project description

derpcache

derpcache is a simple pickle-based caching utility.

It's made for people who love nuking their Jupyter kernels.

from derpcache import cache
import requests

countries = [
    'Afghanistan',
    'Albania',
    # ...
    'Zambia',
    'Zimbabwe'
]

pages = []
for country in countries:
    url = f'https://en.wikipedia.org/wiki/{country}'
    annotation = f'Wikipedia page for {country}'
    page = cache(requests.get, url, _annotation=country)
    pages.append(page)

Why should I use derpcache?

  • You want a cache that will persist between kernel restarts.
  • You want a simple functional interface—no IPython magics needed.
  • You want a reasonable amount of visibility into what's in your cache.
  • You want the ability to set expiration rules.

Expiration

>>> import time
>>> def long_running_func(*args, **kwargs):
...     time.sleep(1200)
...     print('running...')
...     return 'done'
...
>>> expires_after = 300
>>> cache(long_running_func, _expires_after=expires_after)
running...
done
>>> cache(long_running_func)
done
>>> time.sleep(expires_after)
>>> cache(long_running_func)
running...
done

Viewing cached entries

from derpcache import get_index
from pprint import pprint

pprint(get_index(), sort_dicts=False)  # or, pandas.DataFrame.from_records
{"5e39b292": {"callable": "__main__.long_running_func",
              "called_at": "2022-09-06T05:19:14.614796"},
 "b37ab1af": {"callable": "requests.api.get",
              "called_at": "2022-09-06T05:21:35.157183",
              "annotation": "Afghanistan"},
 "f0103017": {"callable": "requests.api.get",
              "called_at": "2022-09-06T05:21:35.814452",
              "annotation": "Albania"},
 "8861f226": {"callable": "requests.api.get",
              "called_at": "2022-09-06T05:21:36.084777",
              "annotation": "Zambia"},
 "19754ec0": {"callable": "requests.api.get",
              "called_at": "2022-09-06T05:21:36.341655",
              "annotation": "Zimbabwe"}}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

derpcache-0.0.4.tar.gz (18.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

derpcache-0.0.4-py3-none-any.whl (18.9 kB view details)

Uploaded Python 3

File details

Details for the file derpcache-0.0.4.tar.gz.

File metadata

  • Download URL: derpcache-0.0.4.tar.gz
  • Upload date:
  • Size: 18.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for derpcache-0.0.4.tar.gz
Algorithm Hash digest
SHA256 058e6ba0c287643cf659bb6e3c36c55c1722b0692ff53b1f3ca457d30e2ca4d7
MD5 472c82fa08cd9e81cab0496a370d97e2
BLAKE2b-256 1329b84dc8d6245b3123a0ae8d2d5825f87df04c75cee8c4a4ff01043171e3df

See more details on using hashes here.

File details

Details for the file derpcache-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: derpcache-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 18.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for derpcache-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 7dd1ceb5916c1bcf7d7d8af0da0959893d0232674cd309da1ee115a123f5c0d2
MD5 13cb30ffc95e4c374299c842fc2e866f
BLAKE2b-256 d3fb548378b74bb431b12e8994b426d3ab96c18a27921cca28cbe72dcc030dbc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page