Class: Auspost::Postie::Cache

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

Constant Summary collapse

@@memcache_host =

Over ride these two class variables to change your memcache settings

"localhost"
@@memcache_port =
"11211"

Instance Method Summary collapse

Constructor Details

#initializeCache

Returns a new instance of Cache.



12
13
14
15
16
17
18
# File 'lib/auspost/postie.rb', line 12

def initialize
  if Object.const_defined? :Rails
    Rails.cache
  else
    @cache = MemCache.new "#{@@memcache_host}:#{@@memcache_port}", :namespace => 'auspost'
  end
end

Instance Method Details

#read(key) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/auspost/postie.rb', line 28

def read(key)
  if @cache
    @cache.get(key) if @cache.servers.map{|s| s.alive?}.include?(true)
  else
    Rails.cache.read(key)
  end
end

#write(key, object) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/auspost/postie.rb', line 20

def write(key, object)
  if @cache
    @cache.add(key, object) if @cache.servers.map{|s| s.alive?}.include?(true)
  else
    Rails.cache.write(key, object)
  end
end