在 Rails 中,为模型、视图、控制器、全部或单独打开代码缓存的标准方法是什么?
运行 Rails 服务器时,通过在 config/environments/development.rb 中使用以下行来表示“缓存所有模型、视图、控制器代码”的标准方法是否正确,
config.cache_classes = true
并且不这样做缓存它们中的任何一个:
config.cache_classes = false
要“有选择地”缓存它们中的任何一个,请使用上面的 false
行,并在 config/environment.rb
中:
config.load_once_paths += %W( #{RAILS_ROOT}/app/models )
它只会缓存模型代码。要缓存控制器代码或视图代码,只需将
#{RAILS_ROOT}/app/controllers
或
#{RAILS_ROOT}/app/views
添加到 %W{ }
内。例如,如果我们只开发视图(HTML和CSS),那么就不需要重新加载 运行服务器时的模型和控制器代码,因此为模型和控制器设置load_once_paths
, 并让 View 代码每次都加载? (有文档讨论这个吗?)
Is it true that the standard way to say "cache all Model, View, Controller code" when running the Rails server, by using the following line in config/environments/development.rb
config.cache_classes = true
and for don't cache any of them:
config.cache_classes = false
and to "selectively" cache any one of them, use the above false
line, and in config/environment.rb
:
config.load_once_paths += %W( #{RAILS_ROOT}/app/models )
which will only cache the Model code. And to cache Controller code or View code, just add either
#{RAILS_ROOT}/app/controllers
or
#{RAILS_ROOT}/app/views
to inside the %W{ }
. For example, if we are only developing the Views (HTML and CSS), then there is no need to reload
Model and Controller code when running the server, so set load_once_paths
for Models and Controllers,
and just let the View code load every time? (is there docs that talk about this?)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,没有文档详细解释这一点,但您可以在这里阅读有关 Rails 配置的信息: http:// guides.rubyonrails.org/configuring.html
至于你的问题,你是绝对正确的:)。
使用 config.load_once_paths 选择性缓存(显然使用 config.cache_classes = false )
并使用 config.cache_classes = true 缓存所有内容
Well, there is no documentation that explains this in detail, but you can read about rails configuration here : http://guides.rubyonrails.org/configuring.html
As for your question, You are absolutely correct :).
use
config.load_once_paths
to cache selectively ( Obviously withconfig.cache_classes = false
)And use
config.cache_classes = true
to cache everything