databaseCaching


πŸ” Caching the Response

You can cache the response by using the cache option in httpGet. Pass a number to specify TTL in milliseconds, or true for a permanent cache.

// Cache for 5 seconds
await httpGet('Main', '/endpoint', { cache: 5000 });

// Permanent cache
await httpGet('Main', '/endpoint', { cache: true });

🧹 Deleting the Cache

You can delete a cached entry in two ways:

1. Using the onRequest hook

const hooks: ShapeRQHooks = {
  onRequest: ({ url, cacheDel }) => {
    cacheDel(url); // Delete cache for this URL before the request
  },
};

await httpGet('Main', '/endpoint', { hooks });

2. Using cacheDel directly


πŸ“¦ Retrieving from Cache

A repeated request to the same URL will return cached data automatically, as long as the TTL hasn't expired (or it's a permanent cache).


Last updated