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.0.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.0-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: autocache_python-0.1.0.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.0.tar.gz
Algorithm Hash digest
SHA256 c60a9c69de3ed593c543120ae6d0cb1ea9b957b769449e5beb5661fe3291ab83
MD5 bbd9e4c2257a67d65a2cc5dc1a1c21e3
BLAKE2b-256 ae4cf068ac73a65d69814dd4c0c338f0d958de8950de31f1d66419bdcd547d3c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for autocache_python-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bf62e8c3293959fc96c75dbee09c816e6c39453341f27f6c135795a439f1a02f
MD5 28fe663bea50d4075536faaa6ab7e3f4
BLAKE2b-256 d1410ea9aac75fde17c35f78ee816104e07bd84ef897c882a44df73af38f801e

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