Class: FoodInfo::CacheAdapters::MemCacheCompatible

Inherits:
Object
  • Object
show all
Defined in:
lib/food_info/cache_adapters/mem_cache_compatible.rb

Instance Method Summary collapse

Constructor Details

#initialize(obj = nil) ⇒ MemCacheCompatible

Returns a new instance of MemCacheCompatible.



5
6
7
8
9
10
11
# File 'lib/food_info/cache_adapters/mem_cache_compatible.rb', line 5

def initialize(obj = nil)
  if obj && obj.respond_to?(:get) && obj.respond_to?(:set)
    @cache = obj
  else
    raise "FoodInfo::CacheAdapters::MemCacheCompatible must be initialized with an object that responds to get and set (look into the Dalli gem)"
  end
end

Instance Method Details

#get(key) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/food_info/cache_adapters/mem_cache_compatible.rb', line 23

def get(key)
  begin
    @cache.get(key)
  rescue Exception => e
    STDERR.puts "FoodInfo Cache Error (get): #{e}"
    return nil
  end
end

#set(key, val) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/food_info/cache_adapters/mem_cache_compatible.rb', line 13

def set(key, val)
  begin
    @cache.set(key, val)
  rescue Exception => e
    STDERR.puts "FoodInfo Cache Error (set): #{e}"
  end
  
  val
end