Skip to main content

AutoCache

Tests PyPI version

A lightweight and easy-to-use caching library for Python with support for automatic cache expiration.

Features

  • Simple @cache() decorator
  • Optional cache expiration (TTL)
  • Cache hit/miss statistics
  • Clear the cache at any time
  • Lightweight with no external dependencies

Installation

pip install autocache

Quick Start

from autocache import cache

@cache()
def slow_function(x):
    print("Running...")
    return x * 2

print(slow_function(5))
print(slow_function(5))

Output:

Running...
10
10

Notice that "Running..." is only printed once because the second call is returned from the cache.

Cache Expiration

from autocache import cache

@cache(expire=5)
def get_data():
    print("Fetching data...")
    return "Hello"

get_data()

After 5 seconds, the cached value expires and the function will run again.

Cache Statistics

from autocache import cache_info

cache_info()

Example output:

Autocache
----------------
Entries: 2
Hits: 5
Misses: 3

Clearing the Cache

from autocache import clear_cache

clear_cache()

Roadmap

  • In-memory caching
  • Cache expiration
  • Cache statistics
  • Clear cache
  • Support both @cache and @cache(...)
  • Maximum cache size
  • Disk caching
  • Async support

License

MIT License

Metadata

Release files for autocache-python 0.2.0

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

Source distribution (sdist)

Source distribution for autocache-python 0.2.0
File Size Uploaded
autocache_python-0.2.0.tar.gz 5.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for autocache-python 0.2.0
File Interpreter ABI Platform
autocache_python-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 10.2 kB

Release files / autocache_python-0.2.0.tar.gz

Download URL autocache_python-0.2.0.tar.gz
Size 5.2 kB
Tags Source
SHA-256 checksum
How to use checksums
02bfca818d12f0894614de530a8d0b0495fce855ebdc3d401cbfb6abaa63a4af
BLAKE2b-256 checksum
How to use checksums
7f3d2420595e256c7e43cac572d3bb7527728ec7a15ab8e8b861c8cca8cec144
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.9

Release files / autocache_python-0.2.0-py3-none-any.whl

Download URL autocache_python-0.2.0-py3-none-any.whl
Size 5.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dffd1cbb70c9fa7fb007122518743c1d81ae528db095786c40d6bf4147c1cd35
BLAKE2b-256 checksum
How to use checksums
eedaa13b7a2ccc4243bfc9a2084c4a02975df7114f720ca0e32cab296a693cd7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.9

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

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