Skip to main content

AutoCache

AutoCache is an experimental Python package that automatically adds in-memory caching to public synchronous functions in the current Python script.

Instead of manually adding a cache decorator to every function, define your functions and call enable() once.

AutoCache v0.1 is an experimental alpha release. It is intended for testing, learning and feedback rather than production applications.

Installation

pip install autocache

Basic usage

import autocache

def expensive_calculation(number):
    print("Calculating...")
    return number ** 2

# Call enable only after defining the functions.
autocache.enable()

print(expensive_calculation(10))  # Cache miss
print(expensive_calculation(10))  # Cache hit

How it works

AutoCache scans public synchronous functions defined in the current __main__ module and replaces them with cached wrappers.

Function arguments are serialized and hashed to generate cache keys. Results are stored in memory for the lifetime of the Python process.

Current limitations

AutoCache v0.1:

  • Uses an in-memory cache
  • Scans only functions available when enable() is called
  • Does not cache asynchronous functions
  • Does not cache generator functions
  • Does not persist results between program executions
  • Has no expiration or maximum cache size
  • Should not be used with functions that perform side effects
  • Should not be used for database writes, file writes, payments or messages

Important warning

Only cache functions whose output depends completely on their arguments.

Do not automatically cache functions that:

  • Modify files or databases
  • Send emails or messages
  • Generate random values
  • Read frequently changing external data
  • Depend on time, global variables or environment state

Version

Current version: 0.1

License

AutoCache is released under the MIT License.

Metadata

Release files for autocacher 0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for autocacher 0.1
File Size Uploaded Provenance
autocacher-0.1.tar.gz 4.0 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for autocacher 0.1
File Interpreter ABI Platform
autocacher-0.1-py3-none-any.whl Python 3 none any Details

Total release size: 8.9 kB

Release files / autocacher-0.1.tar.gz

Download URL autocacher-0.1.tar.gz
Size 4.0 kB
Tags Source
SHA-256 checksum
How to use checksums
bd50854ae8f4d86c1aefaf99d0236e0aa7907b119f102759eb17f1e356ea4c6e
BLAKE2b-256 checksum
How to use checksums
e854d636b14afb542dff0d1d335dc21c0ba0bda5c9711b5913bb71d0266a5534
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.10

Release files / autocacher-0.1-py3-none-any.whl

Download URL autocacher-0.1-py3-none-any.whl
Size 4.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0361f48b8a3388d67699b758559194fac27f43e47e45c59dc5d2bbef75887c0c
BLAKE2b-256 checksum
How to use checksums
3e524a7673f674a38ec02ce65a1971bf872e7117ed2a39caa15d0c07761ecc9d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.10

Security for autocacher 0.1

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.

Release history Release notifications | RSS feed

This release

0.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page