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

Uploaded Python 3

File details

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

File metadata

  • Download URL: funkcache-0.1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 709e4c7fabd03813f83da6153ef7270c839041b80ec1d3852c0b43e9ff7db783
MD5 13bd48a09461461f36ebd3e941640999
BLAKE2b-256 98ad200383ce434378008fcfecc5622d1ca3cdb6d830d8a84bd27a8e57afcbfa

See more details on using hashes here.

File details

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

File metadata

  • Download URL: funkcache-0.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6a9f10851e6ffb3eeb5630b7fc6b1c48bc8ae23c1fc58fa7c83e020a5dc4c66b
MD5 d9be65ab0417e3d0381c1c68ef7a8110
BLAKE2b-256 3d0de7d74400e20082847be721313fe8266c1d179032336da9e5d732745473cd

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