Skip to main content

A lightweight SQLite-based caching manager with TTL support.

Project description

funkcache 😎

funkcache is a lightweight SQLite-based caching manager with TTL (time-to-live) support.
It lets you cache results of function calls, persist them in a local SQLite database,
and automatically expire them after a configurable duration.


Installation

pip install funkcache

Quick Example

from funkcache import SQLiteCache

# Create cache manager (stored in functions_v2.db, default TTL = 10s)
cache_manager = SQLiteCache("functions_v2.db", ttl_seconds=10)

# Free function
@cache_manager.cache(ttl_seconds=5)  # override default TTL → 5s
def add(a, b):
    print("Executing add...")
    return a + b

# Class methods
class Calculator:
    @cache_manager.cache()  # uses default TTL = 10s
    def multiply(self, a, b):
        print("Executing Calculator.multiply...")
        return a * b

class AdvancedCalculator:
    @cache_manager.cache()
    def multiply(self, a, b):
        print("Executing AdvancedCalculator.multiply...")
        return a * b + 1

# Free function calls
print(add(2, 3))   # MISS → executes, caches result
print(add(2, 3))   # HIT  → returns cached result

# Class methods (different cache keys!)
c1 = Calculator()
print(c1.multiply(2, 4))  # MISS
print(c1.multiply(2, 4))  # HIT

c2 = AdvancedCalculator()
print(c2.multiply(2, 4))  # MISS (different class → different key)

Cache Management

# Remove all expired entries
cache_manager.clear_expired_cache()

# Remove all cache entries
cache_manager.clear_cache()

# Remove cache entries for a specific function
cache_manager.clear_cache("add")

Features

  • ✅ SQLite backend (no external dependencies)
  • ✅ TTL-based caching (per-function or default)
  • ✅ Works with free functions and class methods
  • ✅ Logging support for cache hits/misses/clears
  • ✅ Explicit cache clearing (clear_cache, clear_expired_cache)

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

funkcache-0.1.0.tar.gz (3.2 kB view details)

Uploaded Source

Built Distribution

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

funkcache-0.1.0-py3-none-any.whl (2.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: funkcache-0.1.0.tar.gz
  • Upload date:
  • Size: 3.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.18

File hashes

Hashes for funkcache-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b5de5b3da304ba386da2a0c1ed70ec348f1eea4aa1692e6ca8d1e298dbbdfc7a
MD5 1d3473c39f0d98bddfc49890ea2e88e0
BLAKE2b-256 1a59691aa51f819c9f8ad9a2f0aec8e9e8cb704bfff773abc40208455ee4be10

See more details on using hashes here.

File details

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

File metadata

  • Download URL: funkcache-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 2.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.18

File hashes

Hashes for funkcache-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 16451ef88e3712f2db12d97c1438420cdd3f95bfa27775c107f46e551cc7f040
MD5 b89252e9e026f7f5b1de3555d2084930
BLAKE2b-256 30f0bf19ec7937746c150c3c5b7cce2185ea9f363d361f95927bc2c6f41c50ac

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