SoulCache

Query Engine

API Reference for the QueryEngine (higher-level orchestrator)

QueryEngine (Internal)

Internal Implementation

QueryEngine is an internal module of @soulcache/core. It is not exported from the package root and is not part of the public API (@soulcache/core/query does not resolve). The public query API is QueryClient (core) and the useQuery family of hooks (@soulcache/react).

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.

Public API

For consumers, query execution is driven through QueryClient:

import { QueryClient } from '@soulcache/core';
 
const client = new QueryClient();
 
const data = await client.fetchQuery({
  queryKey: ['users'],
  queryFn: async () => {
    const res = await fetch('/api/users');
    return res.json();
  },
});

Or through the React adapter:

import { useQuery } from '@soulcache/react';
 
const { data } = useQuery({
  queryKey: ['users'],
  queryFn: async () => {
    const res = await fetch('/api/users');
    return res.json();
  },
});

Key Differences from QueryClient

FeatureQueryClientQueryEngine (internal)
Retry supportNo (retry config not applied)Yes (via RetryEngine)
Background refetchNoYes (via refetchInterval)
Stale-time-aware readsYes (via defaultOptions.staleTime)Yes (via staleTime option)
Abort signal supportNoYes (passed to queryFn)

On this page