是否有一种方法可以在使用缓存时启用无服务器离线重新加载?

发布于 2025-02-07 19:19:34 字数 281 浏览 4 评论 0原文

无服务器的离线非常慢,因此我启用了缓存以避免“冷启动”。现在,每个lambda的一切都很慢,但是对于任何代码更新,我需要重新启动开发设备。

我使用的

serverless offline --config ./serverless-offline.yml --allowCache --functionCleanupIdleTimeSeconds 10000

是可以设置和检测代码更新并清除整个缓存而无需重新启动的插件吗?甚至只是修改的lambda。

谢谢

Serverless Offline was very slow so I enabled caching to avoid "cold starts". Now everything is slow just one time per lambda but for any code updates, I need to restart the dev env.

I use

serverless offline --config ./serverless-offline.yml --allowCache --functionCleanupIdleTimeSeconds 10000

Is there a plugin that I can set up and detect code updates and clear the whole cache without restarting? Maybe even just the lambda that was modified.

Thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

回忆凄美了谁 2025-02-14 19:19:34

是的,有了Nodemon,您可以取得相同的结果。

NPM I -D nodemon

,然后在您的开始脚本中:

“ start”:“ Nodemon -Exec无线电话离线”

最好的,

Yes, with nodemon you can achieve the same results.

npm i -D nodemon

And then in your start script:

"start": "nodemon --exec serverless offline"

That should work.

Best,

小草泠泠 2025-02-14 19:19:34

您可以尝试减少- functionCleanUpidletimeseconds 5 ,看看是否有帮助,10,000非常高。

--functionCleanupIdleTimeSeconds ...Number of seconds until an idle function is eligible for cleanup

...这意味着您将在10,000秒的时间内缓存近三个小时的源代码。

此外,您可能希望进行一些额外的调试,以确切查看速度下降的位置,在代码本身,DNS,主机机器等中,


编辑:我在使用Docker Image Node时开始遇到错误:16 ...所以我迁移到了Ubuntu 22.04,这解决了我的问题。

FROM ubuntu:22.04

RUN \
    apt-get update &&\
    apt-get -y dist-upgrade &&\
    apt-get -y install curl &&\
    curl -sL https://deb.nodesource.com/setup_16.x | bash - &&\
    apt-get update &&\
    apt-get -y install nodejs

RUN \
    npm install -g [email protected] &&\
    npm install -g serverless

WORKDIR /usr/src/app/

EXPOSE 3000

You might try reducing --functionCleanupIdleTimeSeconds to 5 and see if that helps, 10,000 is pretty high.

--functionCleanupIdleTimeSeconds ...Number of seconds until an idle function is eligible for cleanup

... meaning you'll be caching your source code for nearly three hours at 10,000 seconds.

Additionally, you may wish to do some extra debugging to see exactly where the slow-down is happening, in the code itself, DNS, host machine etc.


Edit: I started having errors with this while using Docker image node:16... so I migrated to Ubuntu 22.04 which solved my problem.

FROM ubuntu:22.04

RUN \
    apt-get update &&\
    apt-get -y dist-upgrade &&\
    apt-get -y install curl &&\
    curl -sL https://deb.nodesource.com/setup_16.x | bash - &&\
    apt-get update &&\
    apt-get -y install nodejs

RUN \
    npm install -g [email protected] &&\
    npm install -g serverless

WORKDIR /usr/src/app/

EXPOSE 3000
固执像三岁 2025-02-14 19:19:34

这是您正在寻找的

无服务器脱机启动 - raloadhandler

This is what you are looking for

serverless offline start --reloadHandler

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文