API.md

@lazarv/react-server/memory-cache

Default in-memory cache provider. Exposes useCache, invalidate, and the client-side helpers used when the runtime's built-in cache is active.

function invalidate(keys: string[]): Promise<void>;

Invalidate the cache for the given keys.

Parameters

Returns — A promise that resolves when the cache is invalidated

function useCache<T>(keys: string[], value: (() => Promise<T>) | T, ttl?: number, force?: boolean): Promise<T>;

Get from cache or set the value in the cache with the given keys for the given time to live.

Parameters

Returns — The cached value

import { useCache } from '@lazarv/react-server'; export default function App() { const data = useCache(['todos'], async () => { const response = await fetch('https://jsonplaceholder.typicode.com/todos'); return response.json(); }, 1000); return <p>{data}</p>; }
type StorageCache = import("./storage-cache").default;