Skip to main content

Caching providers for the AccuralAI LLM pipeline.

Project description

AccuralAI Cache Package

Caching providers for the AccuralAI LLM pipeline.

Available Cache Types

Memory Cache (LRU)

In-memory cache with LRU eviction policy.

from accuralai_cache import MemoryCache, MemoryCacheOptions

cache = MemoryCache(options=MemoryCacheOptions(
    max_entries=512,
    eager_expiry=True
))

Disk Cache (SQLite)

Persistent cache using SQLite database.

from accuralai_cache import DiskCache, DiskCacheOptions

cache = DiskCache(options=DiskCacheOptions(
    path=".cache/accuralai.sqlite",
    size_limit_mb=256
))

Redis Cache

Distributed cache using Redis (requires redis package).

pip install accuralai-cache[redis]
from accuralai_cache import RedisCache, RedisCacheOptions

cache = RedisCache(options=RedisCacheOptions(
    host="localhost",
    port=6379,
    key_prefix="accuralai:cache:"
))

LFU Cache

Least Frequently Used cache with configurable eviction.

from accuralai_cache import LFUCache, LFUCacheOptions

cache = LFUCache(options=LFUCacheOptions(
    max_entries=128,
    eager_expiry=True
))

TTL Cache

Cache that only uses TTL for eviction (no size limits).

from accuralai_cache import TTLCache, TTLCacheOptions

cache = TTLCache(options=TTLCacheOptions(
    default_ttl_s=3600.0,
    eager_expiry=True
))

File Cache

Human-readable JSON file-based cache.

from accuralai_cache import FileCache, FileCacheOptions

cache = FileCache(options=FileCacheOptions(
    directory=".cache/accuralai-file",
    max_files=1000
))

No-Op Cache

Cache that doesn't store anything (for testing/development).

from accuralai_cache import NoOpCache

cache = NoOpCache()

Layered Cache

Combines memory and disk caches.

from accuralai_cache import build_layered_cache

cache = await build_layered_cache(config={
    "memory": {"max_entries": 512},
    "disk": {"path": ".cache/accuralai.sqlite"},
    "promote_on_hit": True
})

Flexible Layered Cache

Advanced layered cache supporting multiple layers and configurable strategies.

from accuralai_cache import build_flexible_layered_cache, PromotionStrategy, WriteStrategy

cache = await build_flexible_layered_cache(config={
    "layers": [
        {"type": "memory", "name": "l1", "priority": 0, "options": {"max_entries": 128}},
        {"type": "redis", "name": "l2", "priority": 1, "options": {"host": "localhost"}},
        {"type": "disk", "name": "l3", "priority": 2, "options": {"path": ".cache/db.sqlite"}},
    ],
    "promotion_strategy": "always",  # or "never", "frequency_based"
    "write_strategy": "write_through",  # or "write_back", "write_around"
    "promotion_threshold": 2
})

Configuration

All caches support common configuration options:

  • default_ttl_s: Default TTL in seconds
  • copy_on_get: Whether to clone responses on get
  • stats_enabled: Enable hit/miss statistics

Usage

from accuralai_core.contracts.models import GenerateRequest, GenerateResponse
from accuralai_cache import MemoryCache, MemoryCacheOptions

cache = MemoryCache(options=MemoryCacheOptions(max_entries=100))

# Store a response
response = GenerateResponse(...)
await cache.set("cache_key", response, ttl_s=300)

# Retrieve
request = GenerateRequest(prompt="test")
cached = await cache.get("cache_key", request=request)

# Invalidate
await cache.invalidate("cache_key")
await cache.invalidate_prefix("prefix:")

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

accuralai_cache-0.2.1.tar.gz (17.0 kB view details)

Uploaded Source

Built Distribution

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

accuralai_cache-0.2.1-py3-none-any.whl (19.7 kB view details)

Uploaded Python 3

File details

Details for the file accuralai_cache-0.2.1.tar.gz.

File metadata

  • Download URL: accuralai_cache-0.2.1.tar.gz
  • Upload date:
  • Size: 17.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for accuralai_cache-0.2.1.tar.gz
Algorithm Hash digest
SHA256 bbc83e47aa84e558ca7415542ed6ac63009bd30b0fa74d0a9e05028936fb18eb
MD5 b089045a7021db77463a73e425374bab
BLAKE2b-256 b4b526dbcd142419c1062837b6981f54d0f78a2707d2a022950f7771a63b3e88

See more details on using hashes here.

File details

Details for the file accuralai_cache-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for accuralai_cache-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ee185a20885080a970c827877fea7d479b74c70d7b8d82ef14c221f1ab88b332
MD5 0fcd7952efd72ffc727d45a19cdd898a
BLAKE2b-256 857f4fafa92d7636683a1e2c153284e4220514839765113e459aa615c292a172

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