Skip to main content

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:")

Metadata

Release files for accuralai-cache 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for accuralai-cache 0.2.1
File Size Uploaded
accuralai_cache-0.2.1.tar.gz 17.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for accuralai-cache 0.2.1
File Interpreter ABI Platform
accuralai_cache-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 36.7 kB

Release files / accuralai_cache-0.2.1.tar.gz

Download URL accuralai_cache-0.2.1.tar.gz
Size 17.0 kB
Tags Source
SHA-256 checksum
How to use checksums
bbc83e47aa84e558ca7415542ed6ac63009bd30b0fa74d0a9e05028936fb18eb
BLAKE2b-256 checksum
How to use checksums
b4b526dbcd142419c1062837b6981f54d0f78a2707d2a022950f7771a63b3e88
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.19

Release files / accuralai_cache-0.2.1-py3-none-any.whl

Download URL accuralai_cache-0.2.1-py3-none-any.whl
Size 19.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ee185a20885080a970c827877fea7d479b74c70d7b8d82ef14c221f1ab88b332
BLAKE2b-256 checksum
How to use checksums
857f4fafa92d7636683a1e2c153284e4220514839765113e459aa615c292a172
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.19

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page