ResponseCache class

Caches AI responses to reduce redundant API calls and costs.

Uses a simple key based on the prompt content. Cached responses expire after a configurable TTL.

Constructors

ResponseCache({Duration ttl = const Duration(hours: 1), int maxEntries = 100})

Properties

hashCode int
The hash code for this object.
no setterinherited
maxEntries int
Maximum number of entries to cache.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
size int
Number of entries currently cached.
no setter
ttl Duration
Time-to-live for cached entries.
final

Methods

clear() → void
Clears all cached entries.
evictExpired() → void
Removes expired entries.
get(String key) AIResponse?
Attempts to retrieve a cached response for the given key.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
put(String key, AIResponse response) → void
Stores a response in the cache with the given key.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

keyFromMessages(List messages, String model) String
Generates a cache key from a list of message contents.