import type { Memorize, MemorizeSetOptions } from './domain/Memorize'; import type { MemorizeCallOptions } from './domain/MemorizeCallOptions'; import type { MemorizeOptions, MemorizeStorageOptions } from './domain/MemorizeOptions'; export type { Serializer, SerializerOption } from './serializer'; export type { Memorize, MemorizeCallOptions, MemorizeOptions, MemorizeSetOptions, MemorizeStorageOptions, }; /** * Creates an in-memory cache instance. * * Returns a {@link Memorize} instance that can be used as Express middleware, * as a direct service-level cache, or as a cache management API — all sharing * the same underlying store. * * **HTTP middleware:** Only `GET` requests with a `2xx` status code are cached. * The cache key is `req.originalUrl`, which includes the query string. * * **Direct cache:** Use {@link Memorize.set}, {@link Memorize.getValue}, and * {@link Memorize.remember} to cache arbitrary values from services, workers, * or any non-HTTP code. * * @param options - Global configuration for the cache instance. * * @example Express middleware * ```ts * const cache = memorize({ ttl: 30_000 }); * * app.get('/users', cache.express(), handler); * app.get('/users', cache(), handler); // backwards-compatible alias * ``` * * @example Service-level caching * ```ts * const cache = memorize({ ttl: 30_000 }); * * const users = await cache.remember('users:list', () => userService.findAll()); * cache.set('config', appConfig); * const config = cache.getValue('config'); * ``` * * @example Cache invalidation * ```ts * app.post('/users', (req, res) => { * users.push(req.body); * cache.delete('/users'); * res.status(201).json(req.body); * }); * ``` * * @example Event hooks * ```ts * cache.on(MemorizeEventType.Set, (e) => console.log('stored', e.key)); * cache.on(MemorizeEventType.Delete, (e) => console.log('deleted', e.key)); * cache.on(MemorizeEventType.Expire, (e) => console.log('expired', e.key)); * cache.on(MemorizeEventType.Empty, () => console.log('cache is empty')); * ``` */ export declare function memorize(options?: MemorizeOptions): Memorize; //# sourceMappingURL=memorize.d.ts.map