import { CacheEntryType, CacheValue, IncrementalCache, WithLastModified } from "@opennextjs/aws/types/overrides.js"; import { IncrementalCacheEntry } from "../internal.js"; type Options = { /** * The mode to use for the regional cache. * * - `short-lived`: Re-use a cache entry for up to a minute after it has been retrieved. * - `long-lived`: Re-use a fetch cache entry until it is revalidated (per-region), * or an ISR/SSG entry for up to 30 minutes. */ mode: "short-lived" | "long-lived"; /** * The default TTL of long-lived cache entries. * When no revalidate is provided, the default age will be used. * * @default `THIRTY_MINUTES_IN_SECONDS` */ defaultLongLivedTtlSec?: number; /** * Whether the regional cache entry should be updated in the background on regional cache hits. * * NOTE: Use the default value unless you know what you are doing. It is set to: * - Next < 16: * `true` in `long-lived` mode when cache purge is not used, `false` otherwise. * - Next >= 16: * `!bypassTagCacheOnCacheHit` */ shouldLazilyUpdateOnCacheHit?: boolean; /** * Whether the tagCache should be skipped on regional cache hits. * * Note: * - Skipping the tagCache allows requests to be handled faster * - When `true`, make sure the cache gets purged * either by enabling the auto cache purging feature or manually * * `true` is not compatible with SWR types of revalidateTag * i.e. on Next 16+, anything different than `revalidateTag("tag", { expire: 0 })`. * That's why the default is `false` for Next 16+ which uses SWR by default. * * NOTE: Use the default value unless you know what you are doing. It is set to: * - Next <16: * `true` if the auto cache purging is enabled, `false` otherwise. * - Next >= 16: * `false` */ bypassTagCacheOnCacheHit?: boolean; }; interface PutToCacheInput { key: string; cacheType?: CacheEntryType; entry: IncrementalCacheEntry; } /** * Wrapper adding a regional cache on an `IncrementalCache` implementation. * * Using a the `RegionalCache` does not directly improves the performance much. * However it allows bypassing the tag cache (see `bypassTagCacheOnCacheHit`) on hits. * That's where bigger perf gain happens. * * We recommend using cache purge. * When cache purge is not enabled, there is a possibility that the Cache API (local to a Data Center) * is out of sync with the cache store (i.e. R2). That's why when cache purge is not enabled the Cache * API is refreshed from the cache store on cache hits (for the long-lived mode). */ declare class RegionalCache implements IncrementalCache { private store; private opts; name: string; protected localCache: Cache | undefined; constructor(store: IncrementalCache, opts: Options); /** * Reads a cache entry from the Cache API, or from the store on a miss. * * Keys without a Cache API URL (see `getCacheUrlKey`) are only read from the store. * * @param key The cache key. * @param cacheType The type of the cache entry. * @returns The cache entry, or `null` when it does not exist or the read fails. */ get(key: string, cacheType?: CacheType): Promise> | null>; set(key: string, value: CacheValue, cacheType?: CacheType): Promise; /** * Deletes a cache entry from the store and from the Cache API. * * @param key The cache key. */ delete(key: string): Promise; protected getCacheInstance(): Promise; /** * Returns the Cache API URL of the entry for `key`. * * The key is opaque and may contain characters that are meaningful in a URL (`%`, `\`, `?`, `#`, ...). * Each segment is encoded so that the URL parser can not resolve the key to the URL of a different entry * (i.e. `x/%2e%2e/admin` or `x\..\admin` to `admin`). * * @param key The cache key. * @param cacheType The type of the cache entry. * @returns The Cache API URL, or `null` when the key contains a `.` or `..` segment that the URL parser would resolve. */ protected getCacheUrlKey(key: string, cacheType?: CacheEntryType): string | null; /** * Stores an entry in the Cache API. * * Nothing is stored when the key has no Cache API URL (see `getCacheUrlKey`). * * @param input The key, type and entry to store. */ protected putToCache({ key, cacheType, entry }: PutToCacheInput): Promise; } /** * A regional cache will wrap an incremental cache and provide faster cache lookups for an entry * when making requests within the region. * * The regional cache uses the Cache API. * * **WARNING:** * If an entry is revalidated on demand in one region (using either `revalidateTag`, `revalidatePath` or `res.revalidate` ), it will trigger an additional revalidation if * a request is made to another region that has an entry stored in its regional cache. * * @param cache Incremental cache instance. * @param opts Options for the regional cache. */ export declare function withRegionalCache(cache: IncrementalCache, opts: Options): RegionalCache; export {};