plugins/ttl/ttl library

TTL (Time-To-Live) plugin for hihook.

Provides conditions and hooks for automatic expiration management.

Metadata Contract

Expects ctx.data['meta'] to contain:

  • created_at: int (milliseconds since epoch)
  • ttl_seconds: int (TTL duration in seconds)

Graceful Degradation

  • No meta: allows operation (no enforcement)
  • Missing TTL fields: allows operation (no enforcement)
  • Complete TTL fields: enforces expiration

Example Usage

final engine = HiEngine();
TtlPlugin().install(engine);

// Or with custom configuration
TtlPlugin(
  ttlSeconds: 3600,
  readEvents: ['read', 'get'],
).install(engine);

Classes

TtlPlugin
TTL Plugin - Time-To-Live expiration management.

Properties

ttlNotExpired → HiCond
Default TTL condition instance.
final

Functions

ttlCleanupHook({String uid = 'ttl:cleanup', List<String> events = const ['read'], HiCond? condition, HiPhase phase = HiPhase.main, int priority = 0}) → HiHook
Creates a TTL cleanup hook that returns HiDelete for expired entries.
ttlNotExpiredCondition({String name = 'ttl:notExpired', String metaKey = 'meta', String createdAtKey = 'created_at', String ttlSecondsKey = 'ttl_seconds', int nowProvider()?}) → HiCond
Creates a TTL condition that checks if an entry is not expired.
ttlStampHook({String uid = 'ttl:stamp', List<String> events = const ['write', 'put'], String metaKey = 'meta', String createdAtKey = 'created_at', int nowProvider()?, HiPhase phase = HiPhase.post, int priority = 0}) → HiHook
Creates a TTL stamp hook that sets creation timestamp on write.