Module: Typhoeus::Request::Cacheable

Included in:
Typhoeus::Request
Defined in:
lib/typhoeus/request/cacheable.rb

Overview

Since:

  • 0.5.0

Instance Method Summary collapse

Instance Method Details

#cache_ttlObject

Since:

  • 0.5.0


22
23
24
# File 'lib/typhoeus/request/cacheable.rb', line 22

def cache_ttl
  options[:cache_ttl]
end

#cacheable?Boolean

Returns:

  • (Boolean)

Since:

  • 0.5.0


9
10
11
# File 'lib/typhoeus/request/cacheable.rb', line 9

def cacheable?
  Typhoeus::Config.cache
end

#response=(response) ⇒ Object

Since:

  • 0.5.0


4
5
6
7
# File 'lib/typhoeus/request/cacheable.rb', line 4

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

#runObject

Since:

  • 0.5.0


13
14
15
16
17
18
19
20
# File 'lib/typhoeus/request/cacheable.rb', line 13

def run
  if cacheable? && response = Typhoeus::Config.cache.get(self)
    response.cached = true
    finish(response)
  else
    super
  end
end