Class: Memcache
- Inherits:
-
Object
- Object
- Memcache
- Defined in:
- lib/Memcache.rb
Overview
this file is part of manqod manqod is distributed under the CDDL licence the author of manqod is Dobai-Pataky Balint([email protected])
Instance Attribute Summary collapse
-
#memcache ⇒ Object
readonly
Returns the value of attribute memcache.
-
#memcache_lib ⇒ Object
readonly
Returns the value of attribute memcache_lib.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
- #get(key) ⇒ Object
-
#initialize(servers, options = {}) ⇒ Memcache
constructor
A new instance of Memcache.
- #to_s ⇒ Object
Constructor Details
#initialize(servers, options = {}) ⇒ Memcache
Returns a new instance of Memcache.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/Memcache.rb', line 6 def initialize(servers,={}) @prefix_key=[:prefix_key] @memcache_lib=nil @memcache=nil @version=nil begin @version=Memcached::VERSION einfo("using memcached(#{version})") @memcache_lib=:memcached rescue =>err begin @version=Dalli::VERSION einfo("falling back memcache to dalli(#{version})") @memcache_lib=:dalli rescue =>err eerror("No memcache lib available, Follow install instructions on http://manqod.sourceforge.net") end end case memcache_lib when :memcached [:default_ttl] = 0 [:timeout] = 30 @memcache = Memcached.new(servers,) when :dalli .delete(:prefix_key) [:expires_in]=0 @memcache = Dalli::Client.new(servers,) else eeror("No memcache lib available") end end |
Instance Attribute Details
#memcache ⇒ Object (readonly)
Returns the value of attribute memcache.
38 39 40 |
# File 'lib/Memcache.rb', line 38 def memcache @memcache end |
#memcache_lib ⇒ Object (readonly)
Returns the value of attribute memcache_lib.
38 39 40 |
# File 'lib/Memcache.rb', line 38 def memcache_lib @memcache_lib end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
38 39 40 |
# File 'lib/Memcache.rb', line 38 def version @version end |
Instance Method Details
#get(key) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/Memcache.rb', line 40 def get(key) case memcache_lib when :memcached begin return memcache.get(key) rescue Memcached::NotFound ewarn("cannot load data for key:#{key.inspect}") return nil end when :dalli if key.class.name == "Array" values=Hash.new key.each{|k| values[k]=dalli_get_one(k)} return values else dalli_get_one(key) end end end |
#to_s ⇒ Object
61 62 63 |
# File 'lib/Memcache.rb', line 61 def to_s "Memcache(#{memcache_lib}-#{version})[#{@prefix_key}]" end |