Learn more about Mintlify
Enter your email to receive updates about new features and product releases.
HTTP request caching with TTL support
import { RequestCache } from "bytekit"; // or import { RequestCache } from "bytekit/request-cache";
const cache = new RequestCache({ ttl: 60000, // 1 minute maxSize: 100 }); // Set cache entry cache.set("/users", responseData, { ttl: 120000 }); // Get cache entry const cached = cache.get("/users"); // Clear cache cache.clear();
import { ApiClient, RequestCache } from "bytekit"; const cache = new RequestCache({ ttl: 60000 }); const api = new ApiClient({ baseUrl: "https://api.example.com", interceptors: { request: async (url, init) => { const cached = cache.get(url); if (cached) { return [url, { ...init, signal: AbortSignal.abort() }]; } return [url, init]; }, response: async (response) => { const data = await response.clone().json(); cache.set(response.url, data); return response; } } });