Rails 永久存储自定义配置

发布于 2024-09-18 21:56:18 字数 193 浏览 0 评论 0原文

我遇到以下情况:我的数据库中有一个应用程序配置,每个请求都需要该配置。由于性能问题,我不想在每个请求上查询此配置。

所以我想要的是在应用程序服务器(mongrel/webbrick/...)启动时查询数据并将其永久存储,直到应用程序服务器重新启动或停止。我怎样才能做到这一点?

感谢您的任何建议

PS:我在 Rails3 上

I got the following situation: I have an application configuration in my database which is needed on every request. I don't want to query this configuration on every request because of performance issues.

So what I want is to query the data when the application server (mongrel/webbrick/...) starts and store it permanently until the application server is rebooted or stopped. How could I achieve this?

Thanks for any advice

PS: I'm on Rails3

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

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

发布评论

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

评论(1

一影成城 2024-09-25 21:56:18

发出请求并将其存储在缓存中。

config_model.rb

  def get_config
    Rails.cache.fetch('the_config'){self.the_config}

Make a request and store it in the cache.

config_model.rb

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