Skip to content

[RFC] Incremental Cache improvements #621

@khuezy

Description

@khuezy

https://github.com/opennextjs/opennextjs-aws/blob/main/packages/open-next/src/overrides/incrementalCache/s3.ts#L43-L58

I had a conversation with the Vercel devs and they said that their cacheHandle makes use of lru-cache to prevent extraneous calls to S3 (or any external datastore). When I was using sst NextjsSite, I noticed lots of S3 hits too:

async get(key, isFetch) {
    const result = await s3Client.send(
      new GetObjectCommand({
        Bucket: CACHE_BUCKET_NAME,
        Key: buildS3Key(key, isFetch ? "fetch" : "cache"),
      }),
    );

    const cacheData = JSON.parse(
      (await result.Body?.transformToString()) ?? "{}",
    );
    return {
      value: cacheData,
      lastModified: result.LastModified?.getTime(),
    };
  },

Whenever a page is reloaded, it would make the S3 call due to the get. Is this correct behavior? Or should we place lru-cache here before hitting S3? eg if cache is null or is stale.

CC: @conico974 @vicb

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions