Module: OpenURI

Defined in:
lib/openuri/common.rb,
lib/openuri/memcached.rb,
lib/openuri/rails-cache.rb

Defined Under Namespace

Classes: Cache

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.open(uri, *rest, &block) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/openuri/common.rb', line 22

def self.open(uri, *rest, &block)
  if Cache.enabled?
    response = Cache::get(uri.to_s)
  end
  
  unless response
    response = openuri_original_open(uri, *rest).read
    Cache::set(uri.to_s, response) if Cache.enabled?
  end

  response = StringIO.new(response)

  if block_given?
    begin
      yield response
    ensure
      response.close
    end
  else
    response
  end
end

Instance Method Details

#original_openObject

:nodoc:



21
# File 'lib/openuri/common.rb', line 21

alias original_open open