Skip to main content

Local disk caching decorator for python function.

Project description

cache_to_disk

Local disk caching decorator for python functions with auto-invalidation.

This is intended to cache functions that both take a long time to run, and have return values that take up too much memory to cache in-memory with redis. The results of the function are pickled and saved to a file, and then unpickled and returned the next time the function is called. The caching is argument specific, so if the function is called with different arguments, the function will be run again. The caching decorator accepts an integer representing the number of days to cache the function for. After this many days, the file for that function will be deleted the next time this module is imported.

Installation

pip install cache_to_disk

Functions:

cache_to_disk(n_days_to_cache) delete_disk_caches_for_function(function_name) delete_old_disk_caches()

Examples:

cache_to_disk

"""
This example caches the function "my_function" for 3 days.
"""

from cache_to_disk import cache_to_disk

@cache_to_disk(3)
def my_function():
    to_return = []
    for i in range(10000):
        for j in range(i):
            to_return.append(i * j ** .23)
    return to_return

delete_disk_caches_for_function

"""
This example invalidates all of the caches for the function "my_function". The function will be invalidated automatically, but this should be used when the function definition has been changed and you want it to re-run.
"""

from cache_to_disk import delete_disk_caches_for_function
delete_disk_caches_for_function('my_function')

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

cache_to_disk-0.0.2.tar.gz (2.6 kB view details)

Uploaded Source

Built Distribution

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

cache_to_disk-0.0.2-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file cache_to_disk-0.0.2.tar.gz.

File metadata

  • Download URL: cache_to_disk-0.0.2.tar.gz
  • Upload date:
  • Size: 2.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.2

File hashes

Hashes for cache_to_disk-0.0.2.tar.gz
Algorithm Hash digest
SHA256 bbbb6d4aa24aa4babd7b169f8397ded45061147e0db319e33304c5d663ab8a44
MD5 f3a0b87a2b3f5309fe3886c6a67a31d7
BLAKE2b-256 84972ffe4e5c4cd12bf508079c71f288057e43c93796272a3f286395839e309c

See more details on using hashes here.

File details

Details for the file cache_to_disk-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: cache_to_disk-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 4.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.2

File hashes

Hashes for cache_to_disk-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4311f9d1b64de4b2e002613ec5ff4255e176ff0867981c40f5f54a5a5d1ad304
MD5 7c8af3716f5107b293a83c42155da9be
BLAKE2b-256 6cd0907821978b7361120cc70ec8acd8734f713ffe26060d22044e3e780314e4

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