Skip to content

API Reference parrot_formdesigner.services.cache

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot_formdesigner.services.cache

View source

Form Cache for the forms abstraction layer.

Provides in-memory TTL-based caching for FormSchema objects with optional Redis backend for distributed caching.

Migrated from parrot/integrations/dialogs/cache.py with:

  • FormSchema instead of FormDefinition
  • Cleaner async-only API (asyncio.Lock throughout)
  • Redis serialization via FormSchema.model_dump_json()
  • No watchdog dependency in core (file watching is optional)

Class FormCache

In-memory TTL cache for FormSchema with optional Redis backend.

Supports:

  • In-memory cache with per-entry TTL expiration
  • Optional Redis backend for distributed/multi-process caching
  • Async-safe with asyncio.Lock
  • Invalidation callbacks for downstream notification
Parameter Type Default Description
ttl_seconds int 3600 Time-to-live in seconds for cached entries. Default: 3600 (1 hour).
redis_url str | None None Optional Redis connection URL. If provided, forms are also stored in Redis for distributed access.

Method FormCache.get

Retrieve a form from cache.

Checks memory cache first, then Redis. Expired entries are evicted.

get(form_id: str) -> FormSchema | None

Parameter Type Default Description
form_id str Form identifier.

Returns: FormSchema | None — FormSchema if found and not expired, None otherwise.

Method FormCache.set

Store a form in cache.

set(form: FormSchema) -> None

Parameter Type Default Description
form FormSchema FormSchema to cache.

Method FormCache.invalidate

Remove a form from cache.

invalidate(form_id: str) -> None

Parameter Type Default Description
form_id str Identifier of the form to evict.

Method FormCache.invalidate_all

Clear all forms from cache.

Note: Per-key on_invalidate callbacks are NOT fired during bulk invalidation. Callers that require per-key notification should use invalidate() individually instead.

invalidate_all() -> None

Method FormCache.on_invalidate

Register a callback for invalidation events.

on_invalidate(callback: Callable[[str], Awaitable[None]]) -> None

Parameter Type Default Description
callback Callable[[str], Awaitable[None]] Async callable receiving the invalidated form_id.

Method FormCache.size

Return number of currently cached (unexpired) forms.

size() -> int

Returns: int — Count of valid cache entries.

Method FormCache.close

Close the Redis connection if open.

close() -> None

Alias FormSchema

Re-exported from parrot_formdesigner.core.schema.FormSchema.

Attribute logger

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally