Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/nasty-boats-boil.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@opennextjs/aws": patch
---

add and expose new `CachedFetchValue` type
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,15 @@ const buildDynamoKey = (key: string) => {
*/
const multiTierCache: IncrementalCache = {
name: "multi-tier-ddb-s3",
async get(key, isFetch) {
async get<IsFetch extends boolean = false>(key: string, isFetch?: IsFetch) {
// First we check the local cache
const localCacheEntry = localCache.get(key);
const localCacheEntry = localCache.get(key) as
| {
value: CacheValue<IsFetch>;
lastModified: number;
}
| undefined;

if (localCacheEntry) {
if (Date.now() - localCacheEntry.lastModified < localCacheTTL) {
debug("Using local cache without checking ddb");
Expand Down
18 changes: 16 additions & 2 deletions packages/open-next/src/types/overrides.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,29 @@ export type CachedFile =
meta?: Meta;
};

export type FetchCache = Object;
// type taken from: https://github.com/vercel/next.js/blob/9a1cd356/packages/next/src/server/response-cache/types.ts#L26-L38
export type CachedFetchValue = {
kind: "FETCH";
data: {
headers: { [k: string]: string };
body: string;
url: string;
status?: number;
// field used by older versions of Next.js (see: https://github.com/vercel/next.js/blob/fda1ecc/packages/next/src/server/response-cache/types.ts#L23)
tags?: string[];
};
// tags are only present with file-system-cache
// fetch cache stores tags outside of cache entry
tags?: string[];
};

export type WithLastModified<T> = {
lastModified?: number;
value?: T;
};

export type CacheValue<IsFetch extends boolean> = (IsFetch extends true
? FetchCache
? CachedFetchValue
: CachedFile) & { revalidate?: number | false };

export type IncrementalCache = {
Expand Down