PVCacheHook class

Defines a hook that executes during cache operations.

Hooks intercept and modify cache behavior at various lifecycle stages:

  • TTL expiration
  • LRU eviction
  • Encryption/decryption
  • Access tracking
  • Validation

Example:

final ttlHook = PVCacheHook(
  eventString: 'ttl_check',
  eventFlow: EventFlow.metaRead,
  priority: 0,
  actionTypes: [ActionType.get],
  hookFunction: (ctx) async {
    final timestamp = ctx.runtimeMeta['_ttl_timestamp'];
    if (timestamp != null && DateTime.now().millisecondsSinceEpoch > timestamp) {
      throw BreakHook('Entry expired');
    }
  },
);

Constructors

PVCacheHook({String? eventString, required EventFlow eventFlow, int priority = 0, List<ActionType> actionTypes = const [ActionType.put, ActionType.get, ActionType.delete, ActionType.clear, ActionType.exists], required Future<void> hookFunction(PVCtx ctx)})
Creates a new cache hook.

Properties

actionTypes List<ActionType>
Operation types this hook responds to.
final
eventFlow EventFlow
Lifecycle stage where this hook executes.
final
eventString String?
Optional identifier for the hook (for debugging/logging).
final
hashCode int
The hash code for this object.
no setterinherited
hookFunction Future<void> Function(PVCtx ctx)
Function that executes when this hook is triggered.
final
priority int
Execution priority within the eventFlow stage.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited