Skip to main content

Simple in-memory caching with TTL support

Project description

cachely ⚡

Simple in-memory caching with TTL support for Python.

Installation

pip install cachely

Usage

Decorator

from cachely import cache

@cache(ttl=300)  # Cache for 5 minutes
def expensive_computation(x):
    return x ** 100

@cache(ttl=60, key_prefix="user")
def get_user(user_id):
    return database.fetch_user(user_id)

Manual Cache

from cachely import Cache

cache = Cache()

# Set with TTL
cache.set("key", "value", ttl=300)

# Get value
value = cache.get("key", default=None)

# Delete
cache.delete("key")

# Clear all
cache.clear()

Features

  • 🕐 TTL (time-to-live) support
  • 🔒 Thread-safe operations
  • 🎯 Function decorator
  • 🧹 Automatic cleanup of expired entries
  • 📊 Cache info and stats

API

Decorator Parameters

Parameter Type Default Description
ttl int None Seconds until expiration
key_prefix str None Prefix for cache keys

Cache Methods

Method Description
get(key, default) Get cached value
set(key, value, ttl) Set cached value
delete(key) Delete cached value
clear() Clear all cache
cleanup() Remove expired entries
size() Number of cached items

License

MIT

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

pycachely_rj-1.0.0.tar.gz (3.3 kB view details)

Uploaded Source

Built Distribution

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

pycachely_rj-1.0.0-py3-none-any.whl (3.7 kB view details)

Uploaded Python 3

File details

Details for the file pycachely_rj-1.0.0.tar.gz.

File metadata

  • Download URL: pycachely_rj-1.0.0.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for pycachely_rj-1.0.0.tar.gz
Algorithm Hash digest
SHA256 b4ca58cb50445983e4e59457501a9fe253c072aae2501ce6d3c52058ff3e649c
MD5 f9431ac0b9484de44db774d2473bf989
BLAKE2b-256 c2df8def9d79bb44e4a98b10a9b476be429e3a07c8a444869416640c9d7ced00

See more details on using hashes here.

File details

Details for the file pycachely_rj-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: pycachely_rj-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 3.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for pycachely_rj-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4a0efd188460578a905f42d1ae2f67989b1952df13cef2273026f241bd809b01
MD5 312fce98fac255f11cb814a523bce0eb
BLAKE2b-256 4e249be90ffe791add4a4fb030b51c2824dec503a3374008d82f2d193e8c4cfe

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