我假设当Rails在环境设置期间加载文件时,这个常量存储在内存中,但是我的偏执部分想知道每次访问该控制器时我是否都在访问文件系统.有人可以建议这方面的最佳做法吗?
class OnboardingController < ApplicationController BRANDS = YAML.load(File.open("#{Rails.root}/config/brands.yml", 'r')) STORES = YAML.load(File.open("#{Rails.root}/config/stores.yml", 'r')) # ...
I assume that this constant is stored in memory when Rails loads
the file during environment setup
是的,当文件被加载/需要时,那里的所有东西都被执行了
和分配.因此它只加载一次.but the paranoid part of me wonders if I’m hitting the filesystem
each time that controller is accessed.
部分正确,在开发模式下,每个常量都没有设置
请求,但这在生产中无关紧要.Can anyone suggest best practices in this area?
保持原样,缓存只将解析转发给第一个请求而不是在启动时,因为老工人你有时间还在运行
精彩评论