Expirable memoization of methods
gem install cachoo
class Cache
extend Cachoo
def now
Time.now.utc
end
cachoo :now # :now gets cached for 5 seconds by default
end
class Cache
extend Cachoo
def now
Time.now.utc
end
cachoo :now, for: 60*60 # :now get cached for 1 hour
end
You can also ahange the time globally:
Cachoo.for = 60*60*24 # 1 day cache
I hate manually expiring memoization
It's an invented word betweeh cache
and achoo
:)