@nhtio/lucid-resourceful/private/utils/cache_event_handler
Process-wide registration + dispatch for the relation-cache EVENT hook (onRelationsCacheEvent). The relation cache emits lifecycle events (hit/miss/store/force/bypass/evict); the host decides what to do with them — write to @nhtio/logger or Adonis' logger, push metrics, trace, or nothing.
Defaults to a no-op so the package stays dependency-neutral: lucid-resourceful never imports a logger of its own, and never bakes in an observability shape.
Interfaces
| Interface | Description |
|---|---|
| RelationCacheEventContext | Structured context for a relation-cache event. Fields are populated per event (e.g. tag/ttl only on store, tag only on evict). |
Type Aliases
| Type Alias | Description |
|---|---|
| RelationCacheEvent | A relation-cache lifecycle event: - hit — a related row was served from cache (no DB query). - miss — a cache miss; the row was loaded from the DB. - store — a freshly-loaded row was written back to the cache. - force — a forceLoad bypassed the read and refreshed the entry. - bypass — caching was skipped (filtering callback / uncacheable relation). - evict — a write-through eviction (deleteByTag) ran on a target's write. |
| RelationsCacheEventHandler | Host-supplied observer for relation-cache lifecycle events. Observe-only: its return value is ignored and a throw from it is swallowed. |
Functions
| Function | Description |
|---|---|
| getDefaultOnRelationsCacheEvent | Reads the currently-registered default event handler. Exposed for completeness; prefer reportRelationCacheEvent. |
| reportRelationCacheEvent | Dispatches a relation-cache event to the effective handler — the model's own $resourcefulOnRelationsCacheEvent → the process-wide default → no-op. |
| resetDefaultOnRelationsCacheEvent | Clears the module-scoped default event handler. Test-only hook: hosts must not call this at runtime. Mirrors resetRelationCacheTargets. |
| setDefaultOnRelationsCacheEvent | Registers (or clears) the process-wide default relation-cache event handler. |