postRead method

  1. @override
void postRead(
  1. PHiveCtx ctx
)

Throws TTLExpiredException when the stored payload is older than allowed.

Routers decide how to react based on the exception behaviors.

Implementation

@override
/// Throws [TTLExpiredException] when the stored payload is older than allowed.
///
/// Routers decide how to react based on the exception behaviors.
void postRead(PHiveCtx ctx) {
  if (ctx.metadata.containsKey('ttl_ms') && ctx.metadata.containsKey('written_at')) {
    final writtenAt = ctx.metadata['written_at'] as int;
    final ttlMs = ctx.metadata['ttl_ms'] as int;
    final now = DateTime.now().millisecondsSinceEpoch;

    if (now - writtenAt > ttlMs) {
      throw TTLExpiredException();
    }
  }
}