T
TanStack3y ago
foreign-sapphire

Can I use custom QueryCache with react-query?

Hi, I have an application where I buffer (cache) data into in-memory cache periodically. The cache structure is nested object which is optimized to read data efficiently. I have BufferManager class to manage writing and reading of cache and BufferClient to handle data fetching logic. The app is similar to hls video player, but instead of buffering video frames, I buffer json objects in order to draw them on canvas. Can I use my custom BufferManager as QueryCache so that I can use react-query to handle data fetching? For example, I want use useInfiniteQuery My buffer (cache) structure looks like this:
type UniqueKey = string;

type Buffer = Record<UniqueKey, SnapshotGroup>
type SnapshotGroup = Record<number, Array<Snapshot>>

type Snapshot = {
datetime: string;
x: number;
y: number;
z: number;
}
type UniqueKey = string;

type Buffer = Record<UniqueKey, SnapshotGroup>
type SnapshotGroup = Record<number, Array<Snapshot>>

type Snapshot = {
datetime: string;
x: number;
y: number;
z: number;
}
2 Replies
generous-apricot
generous-apricot3y ago
you can try to create your own class that extends QueryCache and then pass this into:
const queryClient = new QueryClient({
queryCache: new MyQueryCache()
})
const queryClient = new QueryClient({
queryCache: new MyQueryCache()
})
foreign-sapphire
foreign-sapphireOP3y ago
Thanks

Did you find this page helpful?