module Typhoeus::Request::Cacheable

def cache

def cache
  return nil if options[:cache] === false
  options[:cache] || Typhoeus::Config.cache
end

def cache_ttl

def cache_ttl
  options[:cache_ttl]
end

def cacheable?

def cacheable?
  cache
end

def cached_response

def cached_response
  cacheable? && cache.get(self)
end

def response=(response)

def response=(response)
  cache.set(self, response) if cacheable? && !response.cached?
  super
end

def run

def run
  if response = cached_response
    response.cached = true
    finish(response)
  else
    super
  end
end