cache_method
cache_method copied to clipboard
Feature: cache_method if
It would be interesting to have an "if" option to cache_method. This way we could enable caching with a condition:
def slow_method
...
end
cache_method :slow_method, if: -> { User.count > 100 }
As a workaround I use a second method to test my condition:
def slow_method
if User.count > 100
self.cached_slow_method
else
# Execute the uncached slow code
end
end
def cached_slow_method
...
end
cache_method :cached_slow_method
What do you think ? I can help on this if you like the idea.