1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
module Typhoeus
class Request
module Cacheable
def response=(response)
cache.set(self, response) if cacheable? && !response.cached?
super
end
def cacheable?
cache
end
def run
if response = cached_response
response.cached = true
finish(response)
else
super
end
end
def cached_response
cacheable? && cache.get(self)
end
def cache_ttl
options[:cache_ttl]
end
private
def cache
return nil if options[:cache] === false
options[:cache] || Typhoeus::Config.cache
end
end
end
end
|