Does DiskCache work with Netlify functions (AWS lambdas)? #23
-
Docs say to install |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
That's a great question. Since Lambda supports However, Edit: Actually, I have never used EFS in Lambda before, so I was not sure how it worked. After reading up on it, you likely do not need a custom Cache. You should be able to create EFS through AWS, mount it to your Lambda, and use DiskCache, setting the And yes, you would need to install that package. Unfortunately it cannot be included in Remix-Image, it must be installed separately. The config for the EFS solution would be something along the lines of this: const prodAwsUrl = process.env.DEPLOYMENT_URL;
const prodAwsEFS = process.env.EFS_DIR;
const config = {
selfUrl: process.env.NODE_ENV === "development" ? "http://localhost:3000" : prodAwsUrl,
cache: new DiskCache({
path: process.env.NODE_ENV === "development" ? path.join(os.tmpdir(), "img") : prodAwsEFS,
}),
resolver: fetchImage,
transformer: sharpTransformer,
basePath: process.env.NODE_ENV === "development" ? "public" : "/",
}; |
Beta Was this translation helpful? Give feedback.
That's a great question. Since Lambda supports
tmp
, DiskCache should work. If you try it and it does not work, you may need to change the DiskCache dir, you can see this in the Vercel example.However,
tmp
only holds up to 512 MB and it will eventually be reset between invocations. If you want better performance (cache more transformations, cache transformations longer, faster loading), a better option would be Lambda EFS. To use EFS, you would need to create your own Cache and provide it to the loader. If this is a small project / performance isn't critical,tmp
will work fine and it's free.Edit: Actually, I have never used EFS in Lambda before, so I was not sure how it worked. After re…