Module: OpenURI

Defined in:
lib/openuri_memcached.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
# File 'lib/openuri_memcached.rb', line 22

def self.open(uri, *rest, &block)
  if Cache.enabled?
    begin
      response = Cache::get(uri.to_s)
    rescue Memcached::NotFound
      response = false
    end
  end
  
  unless response
    response = openuri_original_open(uri, *rest, &block).read
    Cache::set(uri.to_s, response) if Cache.enabled?
  end
  StringIO.new(response)
end

Instance Method Details

#original_openObject

:nodoc:



21
# File 'lib/openuri_memcached.rb', line 21

alias original_open open