Skip to main content

A lightweight Python caching library with TTL expiration support

Project description

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

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.2.0.tar.gz (5.2 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.2.0-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: autocache_python-0.2.0.tar.gz
  • Upload date:
  • Size: 5.2 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.2.0.tar.gz
Algorithm Hash digest
SHA256 02bfca818d12f0894614de530a8d0b0495fce855ebdc3d401cbfb6abaa63a4af
MD5 d5d220e48816ac17d2c36279db6a01f4
BLAKE2b-256 7f3d2420595e256c7e43cac572d3bb7527728ec7a15ab8e8b861c8cca8cec144

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for autocache_python-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dffd1cbb70c9fa7fb007122518743c1d81ae528db095786c40d6bf4147c1cd35
MD5 9df17761dbca0872521fe9f6dfe2edd0
BLAKE2b-256 eedaa13b7a2ccc4243bfc9a2084c4a02975df7114f720ca0e32cab296a693cd7

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