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.0.tar.gz (16.5 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.0-py3-none-any.whl (19.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: accuralai_cache-0.2.0.tar.gz
  • Upload date:
  • Size: 16.5 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.0.tar.gz
Algorithm Hash digest
SHA256 7bac0038dd75822ae37f0ab5fda34b203db6e5714d03b245c992851d37f264ca
MD5 0b44cb6723ddbad6bc496fa5079e05b8
BLAKE2b-256 3c6b4e9be688d02057fb7c131961a0fc725845c006682a92ed7da2fcfba6e57e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for accuralai_cache-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 79babff70478252624878d883bc001fe66277204866b4ad5b412ad0d7d612daa
MD5 39fe6c7c03b99dfc071fa0c9e349e64d
BLAKE2b-256 de8ae01e833c35db1bbf7e0fe51c6a71e85a4a861fc8a4877824195dfa735710

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