SoulCache

Query Engine

API Reference for the QueryEngine (higher-level orchestrator)

QueryEngine

The QueryEngine is a higher-level orchestrator that wraps QueryClient with additional features like automatic retry (via RetryEngine), background refetch intervals, and stale-time-aware cache reads.

Access

import { QueryEngine } from '@soulcache/core/query';
 
const engine = new QueryEngine({
  staleTime: 5000,
  refetchInterval: 30000,
});
 
// Execute with retry support
const data = await engine.executeQuery({
  queryKey: ['users'],
  queryFn: async (signal) => {
    const res = await fetch('/api/users', { signal });
    return res.json();
  },
  retry: { maxRetries: 3, baseDelay: 1000 },
});
 
// Access underlying QueryClient
const client = engine.client;

Key Differences from QueryClient

FeatureQueryClientQueryEngine
Retry supportNoYes (via RetryEngine)
Background refetchNoYes (via refetchInterval)
Stale-time-aware readsNoYes (via staleTime option)
Abort signal supportNoYes (passed to queryFn)

On this page