Ruby on Rails 可以“只要代码不更改”就缓存控制器吗?
在工作中,我们遇到一种情况,当
script/server
运行时,所有控制器代码都会被缓存。这是为了加快 开发服务器。但这意味着每当我们改变 控制器代码,我们需要重新启动服务器。
所以我们可以一起关闭控制器代码的缓存。但 难道不能有类似于包含 javascript 的机制吗?
foo.js?1275647624 <--- UNIX timestamp
只要没有代码更改,就使用缓存版本, 但是当代码更改时重新编译它?
可能是因为我们经常使用 HAML 和 SASS,加载一些页面(例如 网站的主页)在开发环境中可能需要 40 秒,并且 相当长。
At work, we have a situation where when
script/server
is run, then all the controller code is cached. This is to speed up the
development server. But that will mean that whenever we change the
controller code, we need to restart the server.
So we can turn off the caching of controller code all together. But
can't there be mechanism that is similar to the inclusion of javascript
foo.js?1275647624 <--- UNIX timestamp
which is to use the cached version as long as there is no code change,
but recompile it when there is code change?
Maybe because we use HAML and SASS a lot, loading some page (such as the
homepage of the site) can take 40 seconds on the dev environment and it
is quite long.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
默认情况下,Rails 将为开发环境中的每个请求重新加载您的类。这应该确保任何更改都被接受。类通常仅在生产环境中运行时才会被缓存,或者如果您设置了临时环境,则可能会被缓存。
显然我不了解您的应用程序,但在开发中加载主页的 40 秒听起来很长。日志中是否有错误?
By default Rails will reload your classes for every request in the development environment. This should ensure that any changes are picked up. Classes are usually only cached when running in the production environment, or possibly if you have a staging environment set up.
Obviously I don't know your application, but 40 seconds to load a home page in development sounds like a long time. Are there any errors in the log?