Class: OpenURI::Cache

Inherits:
Object
  • Object
show all
Defined in:
lib/openuri_memcached.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.expiryObject

How long your caches will be kept for (in seconds)



79
80
81
# File 'lib/openuri_memcached.rb', line 79

def expiry
  @expiry ||= 60 * 10
end

.hostObject



83
84
85
# File 'lib/openuri_memcached.rb', line 83

def host
  @host ||= "127.0.0.1:11211"
end

Class Method Details

.disable!Object

Disable caching - all queries will be run directly using the standard OpenURI ‘open` method.



62
63
64
# File 'lib/openuri_memcached.rb', line 62

def disable!
  @cache_enabled = false
end

.disabled?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/openuri_memcached.rb', line 66

def disabled?
  !@cache_enabled
end

.enable!Object

Enable caching



51
52
53
54
55
56
57
58
# File 'lib/openuri_memcached.rb', line 51

def enable!
  @cache ||= Memcached.new(host, {
    :namespace => 'openuri', 
    :no_block => true,
    :buffer_requests => true
  })
  @cache_enabled = true
end

.enabled?Boolean

Is the cache enabled?

Returns:

  • (Boolean)


46
47
48
# File 'lib/openuri_memcached.rb', line 46

def enabled?
  @cache_enabled
end

.get(key) ⇒ Object



70
71
72
# File 'lib/openuri_memcached.rb', line 70

def get(key)
  @cache.get(key)
end

.set(key, value) ⇒ Object



74
75
76
# File 'lib/openuri_memcached.rb', line 74

def set(key, value)
  @cache.set(key, value, expiry)
end