-
-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add example for AWS S3 #123
Comments
Also applies here |
Hi everyone, wanted to contribute my AWS S3 implementation (I use DO Spaces, but should be similar for other S3 compatible services) please feel free to contribute to improve upon this concept or highlight where I got it wrong, I just threw it together but seems to work. I use Next14 pages router so I don't think I can make use of the Thanks for creating this library :)
|
Hey @better-salmon ! Just wanted to report back with a question... So I ran in to an issue when I build and deploy a new version of my code where existing cached pages first show an empty page and if I refresh it loads the web page correctly. Given I think i understand how ISR works, I understand why this is:
I am wondering how I should be handling this scenario since the initial page view will try to reference a page from cache with JS files that no longer can be referenced (since the JS file ids change on each build) Do i need to add a deployment webhook that clears my cache in my S3 bucket on deployment, or did I mess something up in my config above? Curious about your thoughts or how you handle this on Redis implementations. For reference, I've exported the .json that is saved in my S3 bucket so you can see the diff. Old === what is in the cache after a new build but without a refresh Thanks for your time! EDIT: if you're curious how I'm doing SSG here is an example that I use on a page. I just default to dynamically generate all paths after deployment (hence the empty array)
|
Hi @uncvrd, I apologize for the delay in getting back to you. I want to start by thanking you for your participation! Your example will be added to the documentation, but I need some time to test it. Now, let me answer your questions. When deploying a new build of your application, it's important not to use the cache from the previous builds. To automate this process, I recommend using two methods simultaneously:
You can find instructions on using Build Id as a cache key prefix here: Build Id as a Prefix Key. |
Hey @better-salmon no worries - thanks for the response! Thanks for the guidance on the build id, I'll work on implementing. I really wanted to enforce a shorter bucket lifecycle policy to automatically delete items after a small period of time so that I wouldn't have to create a webhook to delete all cache on build. All my SSG pages have a TTL of 60 seconds and S3 doesn't allow a lifecycle policy less than a day. I already use NATS in my infrastructure https://nats.io/ (it can be used like a KV similar to Redis) so I figured I'd build out a handler for that to test too. For this I've defined a lifecycle of 70 seconds (just a bit longer than my TTL for SSG) and it seems to be working great with minimal downtime between builds since the TTL defined on my "kv cache" is so small Anyways, I took most of your inner workings for Redis and built this out:
Do note, that I dont create the revalidatedKeys object when initializing this like you do for Redis, that happens in the Anyways I hope this example is useful too! |
Thank you for your attention and contribution! I noticed one thing in your code that can be improved. You do not need to use the I am working on a new documentation section that will sufficiently cover these nuances. |
Gotcha - thanks for the feedback! I'll check the docs regarding error handling 🙏 |
Hi @better-salmon! I'm trying to find where in the docs you write about the nuances of using try/catch? Was this ever added? If not, is it the still the case you shouldn't use try/catch within the methods? And if we don't use try/catch how do we handle 404 scenarios? Thank you! |
Hello @dross15! It is mentioned here https://caching-tools.github.io/next-shared-cache/api-reference/handler#overview and also in the Guide of creating a custom Handler. |
No description provided.
The text was updated successfully, but these errors were encountered: