I got this to work by flipping uncached
to cache
. I was experimenting on the Post
model, but you could probably drop this in your helper just as easily:
class Post < ActiveRecord::Base
def self.random_posts(n = 3)
cache do
random.limit(n)
end
end
end
For two calls of the method using uncached
, the ActiveRecord log lines are Post Load ...
and CACHE ...
, but using cache
, they are both Post Load...
. I really wish I could explain why this works, but it's completely counterintuitive and makes no sense to me.