SoulCache

Plugins

Learn about SoulCache's plugin system for extensibility

Plugins

The Plugin System allows you to extend SoulCache with custom behavior.

Usage

SoulCache provides a plugin infrastructure for internal extension. The plugin system is an internal module of @soulcache/core: PluginManager, Plugin, and PluginContext are not exported from the package root, there is no plugins option on QueryClientConfig, and the @soulcache/core/plugin subpath does not resolve. There is no public plugin registration API in the current release.

// The plugin system is internal to @soulcache/core.
// It is not exported and cannot be imported by consumers.

Lifecycle

Plugins go through a well-defined lifecycle:

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

Features

Dependency Resolution

Automatic dependency resolution ensures correct load order

Error Isolation

Each hook is isolated so errors don't cascade

State Machine

Well-defined lifecycle states for predictable behavior

Dependency Checking

Automatic verification of plugin dependencies

Best Practices

Plugin Guidelines

  • Keep plugins small — Single responsibility principle
  • Handle errors — Hooks are isolated but should be robust
  • Declare dependencies — Ensure correct load order
  • Clean up — Use onDispose for resource cleanup

On this page