如何在时间限制内刷新模型

问题描述 投票:0回答:1

大家好,感谢您帮助我解决问题

Ruby版本:2.6.5

Rails版本:Rails 6.0.2.1

数据库:oracle

我当前正在获取数据并以图表形式输出在我看来,因此我该如何每小时更新一次图表,而不是通过从数据库中获取数据来不断更新它

ruby-on-rails ruby oracle
1个回答
0
投票

您可能想尝试的是称为低级缓存https://guides.rubyonrails.org/caching_with_rails.html#low-level-caching的缓存技术>

class Product < ApplicationRecord
  def chart_data
    Rails.cache.fetch("#{cache_key_with_version}/chart_data", expires_in: 1.hours) do
      find_chart_data(id)
    end
  end
end
© www.soinside.com 2019 - 2024. All rights reserved.