Skip to main content

A memoize-like decorator that caches to disk.

Project description

diskoize:memoize::disk:memory

What is this

Often when I use @functools.lru_cache I find that the cache is erased between python process restarts. This library is the fix!

import diskoize
import requests

@diskoize.diskoize("scrape_cache.db")
def scrape(url):
  return requests.request(url)


scrape("google.com") # <-- will run only once, even after rerunning this script.

You need to manually delete the cache if you change the function's input-output behavior.

Tests

We use pytest for testing. To run the tests, you can use the following command:

pytest

This will run all the tests in the tests directory. You can also run a specific test file by providing the path to the file:

pytest tests/test_file.py

Remarks

  • There is a tension between making this library understandable and making it easy to use. -- we always give the option of explicitly naming the backing sqlite database file. -- for autonaming, we currently create or reuse a file in the system temp directory which is based based on the diskoized function's name. It is up to the user to delete invalidated caches. So autonaming should probably only be used for quick-and-dirty experiments where we don't expect to come back to the code after a long while.

TODOs

  • add option in_memory (default False) to store the cache in memory, always with persistent backing.
  • make the tests actually test separate processes accessing the same cache
  • add methods for interacting with the cache
  • add more examples
  • add flush() method, and a lru_cache to support it
  • fix _make_key

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

diskoize-0.1.0.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

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

diskoize-0.1.0-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file diskoize-0.1.0.tar.gz.

File metadata

  • Download URL: diskoize-0.1.0.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for diskoize-0.1.0.tar.gz
Algorithm Hash digest
SHA256 4e41290d8214886a8144613753298facc9781691c8879672d47ee50968bc0cdb
MD5 c8de05dc3f84317dce3cfb2d936039b8
BLAKE2b-256 3943118f85df951d44e2ccc2b6b4c2714595b81fad456e34b8a6ec760712a7eb

See more details on using hashes here.

File details

Details for the file diskoize-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: diskoize-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for diskoize-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 559e64a4ccc0979f0aea1106e7fa410fe25f977507238b6052b581cb531a0350
MD5 65db0eb3e816174cdfa7a7419b74b046
BLAKE2b-256 d8dfc9207d74e6037aa3ff38db7109534bfd58fd287712e0745a4daf0af3054c

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