Skip to main content

A lightweight Python caching library with TTL expiration support

Project description

AutoCache

Tests

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

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

autocache_python-0.1.1.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

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

autocache_python-0.1.1-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file autocache_python-0.1.1.tar.gz.

File metadata

  • Download URL: autocache_python-0.1.1.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for autocache_python-0.1.1.tar.gz
Algorithm Hash digest
SHA256 f4f468e4a9506effee5bf9e1818e3d3c2bce74896e700b68e87fc741aca664b3
MD5 76472c628ad1998a7b0cdc4348a7266d
BLAKE2b-256 534fbd0f26c3dcab2479a80c2417e225f04e0e92cd3cd7005d4ea948fb03857f

See more details on using hashes here.

File details

Details for the file autocache_python-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for autocache_python-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b5d777c76797bc63c8038fb2dd92de29526ef62b6b67dea636c6ea702c2c7354
MD5 a78ca0d539f576453719e656f14e6a50
BLAKE2b-256 8f5305c0a7a97e483367dadac7ef186907640df6683ffa5adb42204656326b2d

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