开发者

Rails cache do inside module

开发者 https://www.devze.com 2022-12-19 13:12 出处:网络
Hot can I use cache do command inside module? Example module MyModule def self.some_method(str) cache str do

Hot can I use cache do command inside module?

Example

module MyModule
  def self.some_method(str)
    cache str do
      开发者_JAVA技巧... some code ...
    end
  end
end

Thx!


Assuming you're using Rails, you can do it like so:

module MyModule
  def self.some_method(str)
    Rails.cache.fetch(str) do
      # ...
    end
  end
end
0

精彩评论

暂无评论...
验证码 换一张
取 消