ttlCleanupHook function

HiHook ttlCleanupHook({
  1. String uid = 'ttl:cleanup',
  2. List<String> events = const ['read'],
  3. HiCond? condition,
  4. HiPhase phase = HiPhase.main,
  5. int priority = 0,
})

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 ttlNotExpired
  • phase: Hook phase, defaults to HiPhase.main
  • priority: 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(),
  );
}