Use app.cacheInvalidation() to define custom logic for when cached results should be thrown out and recomputed. Useful when helper functions or external dependencies change outside the eval function body, or when you want time-based expiry.
Only the last call to app.cacheInvalidation() is active. Combine all your invalidation conditions into a single hook using if-statements.
import { createApp } from 'claudeye';
const app = createApp();
// ── Evals ────────────────────────────────────────────────────────
app.eval('under-50-turns', ({ stats }) => ({
pass: stats.turnCount <= 50,
score: Math.max(0, 1 - stats.turnCount / 100),
message: `${stats.turnCount} turn(s)`,
}));
app.eval('has-completion', ({ entries }) => {
const last = [...entries].reverse().find(e => e.type === 'assistant');
const hasText = last?.message?.content?.some?.(b => b.type === 'text');
return {
pass: !!hasText,
score: hasText ? 1.0 : 0,
message: hasText ? 'Ended with text' : 'No final text response',
};
});
// ── Enrichments ──────────────────────────────────────────────────
app.enrich('overview', ({ stats }) => ({
'Turns': stats.turnCount,
'Tool Calls': stats.toolCallCount,
}));
// ── Cache Invalidation Hook ──────────────────────────────────────
// Combine all invalidation logic into one hook — only the last
// app.cacheInvalidation() call is active.
app.cacheInvalidation((ctx) => {
const ageMs = Date.now() - new Date(ctx.cachedAt).getTime();
const twentyFourHours = 24 * 60 * 60 * 1000;
// Time-based: discard any cached entry older than 24 hours
if (ageMs > twentyFourHours) return true;
// Value-based: re-run any eval that scored 0
if (ctx.itemKind === 'evals' && ctx.cachedValue?.score === 0) return true;
// Compound: re-run enrichments older than 1h in a specific project
if (
ctx.itemKind === 'enrichments' &&
ctx.projectName === 'my-critical-project' &&
ageMs > 60 * 60 * 1000
) return true;
return false;
});
app.listen();
claudeye --evals ./cache-invalidation.js
Hook context fields
| Field | Description |
|---|
itemName | Eval or enrichment name |
itemKind | "evals" or "enrichments" |
cachedAt | ISO timestamp of when the result was cached |
cachedValue | The full cached result object |
projectName | Project name |
sessionId | Session ID |
contentHash | Hash of the session file content |
itemCodeHash | Hash of the eval/enrichment function code |