ttlCleanupHook function
HiHook
ttlCleanupHook({})
Creates a TTL cleanup hook that returns HiDelete for expired entries.
This hook runs when entries ARE expired (inverted TTL condition).
Consumer should handle HiDelete result by removing the entry from storage.
Parameters
uid: Unique hook identifier, defaults to 'ttl:cleanup'events: Events to listen for, defaults to'read'condition: TTL condition to invert, defaults to ttlNotExpiredphase: Hook phase, defaults toHiPhase.mainpriority: Hook priority, defaults to 0
Example
engine.register(ttlCleanupHook());
// Or with custom events
engine.register(ttlCleanupHook(
events: ['read', 'get'],
));
Implementation
HiHook<dynamic, dynamic> ttlCleanupHook({
String uid = 'ttl:cleanup',
List<String> events = const ['read'],
HiCond? condition,
HiPhase phase = HiPhase.main,
int priority = 0,
}) {
final cond = condition ?? ttlNotExpired;
return HiHook<dynamic, dynamic>(
uid: uid,
events: events,
phase: phase,
priority: priority,
conditions: [~cond], // Inverted: runs when expired
handler: (payload, ctx) => const HiDelete(),
);
}