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
23 changes: 11 additions & 12 deletions src/cacheHandler/strategy/s3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ export class S3Cache implements CacheStrategy {
)
}

async get(pageKey: string, cacheKey: string, ctx: CacheContext): Promise<CacheEntry | null> {
async get(pageKey: string, cacheKey: string): Promise<CacheEntry | null> {
if (!this.client) return null

const pageData = await this.client
.getObject({
Bucket: this.bucketName,
Key: `${pageKey}/${cacheKey}.${ctx.isAppRouter ? CacheExtension.RSC : CacheExtension.JSON}`
Key: `${pageKey}/${cacheKey}.${CacheExtension.JSON}`
})
.catch((error) => {
if (NOT_FOUND_ERROR.includes(error.name)) return null
Expand All @@ -58,7 +58,7 @@ export class S3Cache implements CacheStrategy {

const response = await pageData.Body.transformToString('utf-8')

return ctx.isAppRouter ? response : JSON.parse(response)
return JSON.parse(response)
}

async set(pageKey: string, cacheKey: string, data: CacheEntry, ctx: CacheContext): Promise<void> {
Expand All @@ -82,6 +82,14 @@ export class S3Cache implements CacheStrategy {
ContentType: 'text/html'
})
)
promises.push(
this.client.putObject({
...input,
Key: `${input.Key}.${CacheExtension.JSON}`,
Body: JSON.stringify(data),
ContentType: 'application/json'
})
)
if (ctx.isAppRouter) {
promises.push(
this.client.putObject({
Expand All @@ -91,15 +99,6 @@ export class S3Cache implements CacheStrategy {
ContentType: 'text/x-component'
})
)
} else {
promises.push(
this.client.putObject({
...input,
Key: `${input.Key}.${CacheExtension.JSON}`,
Body: JSON.stringify(data.value.pageData),
ContentType: 'application/json'
})
)
}
} else {
promises.push(
Expand Down
2 changes: 1 addition & 1 deletion src/lambdas/edgeRouting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export const handler = async (

if (isFileExists) {
// Modify s3 path request
request.uri = `/${s3Key}${queryParams}`
request.uri = `/${s3Key}`

// If file exists, allow the request to proceed to S3
callback(null, request)
Expand Down