PrismResponseCache class

Caches AI responses by prompt hash so repeated calls don't re-bill.

Keyed by SHA-256 of the prompt + model + temperature. Stores the raw response string and an optional expiry.

final cache = PrismResponseCache();
final key = cache.keyFor(prompt, model: 'gpt-4o-mini');
final cached = cache.get(key);
if (cached != null) return cached;
// …otherwise call the AI and store the response
cache.put(key, response);

Constructors

PrismResponseCache({int maxEntries = 100})
Creates a response cache.

Properties

hashCode → int
The hash code for this object.
no setterinherited
length → int
Number of cached entries.
no setter
maxEntries → int
Maximum number of cached responses. Oldest entries are evicted first.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

clear() → void
Clears the cache.
get(String key) → String?
Returns the cached response for key, or null if expired or absent.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
put(String key, String response, {Duration? ttl}) → void
Stores response under key.
toString() → String
A string representation of this object.
inherited

Operators

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

Static Methods

keyFor(String prompt, {required String model, double? temperature}) → String
Computes a cache key from the prompt, model and temperature.