A simple Ruby library for caching the results of a call to any method or function call.
Great for speeding up program execution for when making long calls to things like web services.
Install from the command line
# gem install callcache
The following will call exp_fun and print out the results of the call. The result will be stored in a file cache, and the next time the same call is made, the cached results will be returned.
require 'call_cache'
def exp_fun( start_num, end_num )
ret_val = 1
start_num.upto( end_num ) do |num|
ret_val = ret_val * num
end
return ret_val.to_s.size
end
blog_source = CallCache.call( 'Net::HTTP.get', :pars => [URI.parse('http://feeds.feedburner.com/adamw523?format=xml')] );
p blog_source.size
p CallCache.call( 'exp_fun', :pars => [1, 10000], :options => {:ttl => 10})