Skip to main content
QueryClient manages cache reads, writes, invalidations, and subscriptions. It is exposed as kweri.queryClient for advanced use cases — in most applications you’ll interact with the Kweri facade instead.

Constructor

new QueryClient(store: CacheStore, observers: ObserverRegistry)

Methods

getQueryKey

getQueryKey<E extends Endpoint>(endpoint: E, params: unknown): string
Returns the serialized cache key for an endpoint + params pair.

invalidateQuery

invalidateQuery<E extends Endpoint>(endpoint: E, params: unknown): void
Marks the entry for endpoint + params as stale by setting updatedAt = 0.

invalidateByKey

invalidateByKey(key: string): void
Invalidates by raw cache key string.

invalidateByPath

invalidateByPath(pattern: string | RegExp): void
Invalidates all entries whose key contains/matches pattern.

removeQuery

removeQuery<E extends Endpoint>(endpoint: E, params: unknown): void
Deletes the cache entry.

removeByKey

removeByKey(key: string): void
Deletes by raw key string.

getCachedData

getCachedData<E extends Endpoint>(endpoint: E, params: unknown): unknown
Returns cached data or undefined.

setCachedData

setCachedData<E extends Endpoint>(endpoint: E, params: unknown, data: unknown): void
Writes data into the cache and notifies observers.

subscribe

subscribe<E extends Endpoint>(
  endpoint: E,
  params: unknown,
  callback: (entry: CacheEntry) => void
): () => void
Subscribes to cache changes for a specific query.

CacheStore

The underlying storage used by QueryClient. Exposed as kweri.queryClient → internal store.
class CacheStore {
  get(key: string): CacheEntry | undefined
  set(key: string, partial: Partial<CacheEntry>): void  // merges
  delete(key: string): boolean
  has(key: string): boolean
  entries(): IterableIterator<[string, CacheEntry]>
  keys(): IterableIterator<string>
  values(): IterableIterator<CacheEntry>
  size: number
  clear(): void
}

ObserverRegistry

Pub/sub registry for cache entry notifications.
class ObserverRegistry {
  subscribe(key: string, callback: Callback): Unsubscribe
  notify(key: string, entry: CacheEntry): void
  subscribeAll(callback: GlobalNotifyCallback): Unsubscribe
  getObserverCount(key: string): number
  keys(): IterableIterator<string>
  size: number
  clear(key: string): void
  clearAll(): void
}

type Callback             = (entry: CacheEntry) => void
type Unsubscribe          = () => void
type GlobalNotifyCallback = (key: string, entry: CacheEntry) => void