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



26
27
28
# File 'lib/typhoeus/request/cacheable.rb', line 26

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?
  cache
end

#cached_responseObject

Since:

  • 0.5.0



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

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

#response=(response) ⇒ Object

Since:

  • 0.5.0



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

def response=(response)
  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 response = cached_response
    response.cached = true
    finish(response)
  else
    super
  end
end