| Server IP : 159.203.156.69 / Your IP : 216.73.217.172 Web Server : nginx/1.24.0 System : Linux main-ubuntu 6.8.0-71-generic #71-Ubuntu SMP PREEMPT_DYNAMIC Tue Jul 22 16:52:38 UTC 2025 x86_64 User : root ( 0) PHP Version : 8.3.6 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/tanviranik.com/node_modules/vinext/dist/shims/ |
Upload File : |
//#region src/shims/cache-for-request.d.ts
/**
* Cache a factory function's result for the duration of a request.
*
* Returns a function that lazily invokes the factory on first call within
* a request, then returns the cached result for all subsequent calls in
* the same request. Each new request gets a fresh invocation.
*
* The factory function's identity (reference) is the cache key — no
* string keys, no collision risk between modules.
*
* Async factories are supported: the returned Promise is cached, so
* concurrent `await` calls within the same request share one invocation.
* If the Promise rejects, the cached entry is cleared so the next call
* can retry.
*
* Outside a request scope (tests, build-time), the factory runs every
* time with no caching — safe and predictable.
*
* @example
* ```ts
* import { cacheForRequest } from "vinext/cache";
*
* const getPrisma = cacheForRequest(() => {
* const pool = new Pool({ connectionString: env.HYPERDRIVE.connectionString });
* return new PrismaClient({ adapter: new PrismaPg(pool) });
* });
*
* // In a route handler or server component:
* const prisma = getPrisma(); // first call creates, subsequent calls reuse
* ```
*
* @example
* ```ts
* // Async factory — Promise is cached, not re-invoked.
* // If it rejects, the cache is cleared for retry.
* const getDb = cacheForRequest(async () => {
* const pool = new Pool({ connectionString });
* await pool.connect();
* return drizzle(pool);
* });
*
* const db = await getDb();
* ```
*
* @module
*/
/**
* Create a request-scoped cached version of a factory function.
*
* @param factory - Function that creates the value. Called once per request for sync
* factories. Async factories that reject have their cache cleared, allowing retry.
* @returns A function with the same return type that caches the result per request.
*/
declare function cacheForRequest<T>(factory: () => T): () => T;
//#endregion
export { cacheForRequest };
//# sourceMappingURL=cache-for-request.d.ts.map