Class: LS4::MemcachedMDSCache

Inherits:
MDSCache
  • Object
show all
Defined in:
lib/ls4/service/mds_cache_memcached.rb

Instance Method Summary collapse

Constructor Details

#initializeMemcachedMDSCache



24
25
26
# File 'lib/ls4/service/mds_cache_memcached.rb', line 24

def initialize
  require 'memcache'
end

Instance Method Details

#closeObject



43
44
45
# File 'lib/ls4/service/mds_cache_memcached.rb', line 43

def close
  @mc.reset
end

#get(key) ⇒ Object



47
48
49
# File 'lib/ls4/service/mds_cache_memcached.rb', line 47

def get(key)
  @mc.get(key, true)
end

#invalidate(key) ⇒ Object



55
56
57
# File 'lib/ls4/service/mds_cache_memcached.rb', line 55

def invalidate(key)
  @mc.delete(key)
end

#open(expr) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/ls4/service/mds_cache_memcached.rb', line 28

def open(expr)
  @expire = 0
  if m = /\;expire\=(\d+)/.match(expr)
    servers_line = expr[0,m.begin(0)]
    @expire = m[1].to_i
  else
    servers_line = expr
  end
  @servers = servers_line.split(/\s*\,\s*/)
  if @expire == 0
    @expire = 60*60*24
  end
  @mc = MemCache.new(@servers, {:urlencode => false, :compression => false, :multithread => true, :timeout => 1.0})
end

#set(key, val) ⇒ Object



51
52
53
# File 'lib/ls4/service/mds_cache_memcached.rb', line 51

def set(key, val)
  @mc.set(key, val, @expire, true)
end

#to_sObject



59
60
61
# File 'lib/ls4/service/mds_cache_memcached.rb', line 59

def to_s
  "<MemcachedMDSCache servers=#{@servers.join(',')} expire=#{@expire}>"
end