views:

48

answers:

1

Hot can I use cache do command inside module?

Example

module MyModule
  def self.some_method(str)
    cache str do
      ... some code ...
    end
  end
end

Thx!

+2  A: 

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
Josh