Reputation: 564
I need to join two list cached into my Model, to build a new cached list
I've tried the code below but cached_groups
is producing an empty result. Any ideas?
def cached_favgroups
Rails.cache.fetch([self, "fav_groups"]) {fav_groups.to_a}
end
def cached_groups_all
Rails.cache.fetch([self, "groups"])
end
def cached_groups
Rails.cache.fetch(self.cached_groups_all - self.cached_favgroups )
end
Upvotes: 2
Views: 42
Reputation: 6026
You need to add a block to the fetch
method. Try this:
def cached_groups
Rails.cache.fetch([self, "groups_all_favgroups"]) do
self.cached_groups_all - self.cached_favgroups
end
end
Upvotes: 2