SoulCache

PluginManager

Internal architecture - Plugin lifecycle management

PluginManager (Internal)

Internal Implementation

PluginManager is an internal class. Plugins are registered through the QueryClient configuration.

The PluginManager coordinates plugin registration, validation, lifecycle management, and hook execution. It is used internally by the runtime to manage plugin state machines.

Public Usage

Plugins are registered through the QueryClient configuration:

// Plugin types are internal to @soulcache/core
// Import from the plugin subpath when it becomes public
import type { Plugin, PluginContext } from '@soulcache/core/plugin';
 
const myPlugin: Plugin = {
  metadata: {
    id: 'logging',
    name: 'Logging Plugin',
    version: '1.0.0',
  },
  onAfterInit: (ctx: PluginContext) => {
    ctx.log('info', 'Plugin initialized');
  },
  onBeforeQuery: (queryKey: unknown[], ctx: PluginContext) => {
    ctx.log('info', `Query starting: ${queryKey.join('/')}`);
  },
  onAfterQuery: (queryKey: unknown[], ctx: PluginContext) => {
    ctx.log('info', `Query completed: ${queryKey.join('/')}`);
  },
};

Plugin Lifecycle

Plugins go through well-defined states:

StateDescription
discoveredPlugin found
validatedMetadata valid
registeredAdded to manager
initializedonBeforeInit/onAfterInit called
activeHooks running
suspendedTemporarily disabled
resumingBeing resumed from suspension
stoppingDisposal in progress
disposedCleaned up
removedUnregistered from manager
errorInitialization failed

Hooks

HookWhen
onBeforeInitBefore initialization
onAfterInitAfter initialization
onBeforeQueryBefore query execution
onAfterQueryAfter query completion
onBeforeMutationBefore mutation
onAfterMutationAfter mutation
onCacheUpdatedCache entry updated
onCacheInvalidatedCache entry invalidated
onShutdownRuntime shutdown
onSuspendPlugin suspended
onResumePlugin resumed
onDisposePlugin disposed

On this page