Class: Moneta::Adapters::TokyoCabinet

Inherits:
Object
  • Object
show all
Includes:
Defaults
Defined in:
lib/moneta/adapters/tokyo_cabinet.rb

Instance Method Summary collapse

Methods included from Defaults

#[]=, #fetch

Constructor Details

#initialize(options = {}) ⇒ TokyoCabinet

Returns a new instance of TokyoCabinet.



13
14
15
16
17
18
19
# File 'lib/moneta/adapters/tokyo_cabinet.rb', line 13

def initialize(options = {})
  file = options[:file]
  @cache = ::TokyoCabinet::HDB.new
  unless @cache.open(file, ::TokyoCabinet::HDB::OWRITER | ::TokyoCabinet::HDB::OCREAT)
    puts @cache.errmsg(@cache.ecode)
  end
end

Instance Method Details

#[](key) ⇒ Object



21
22
23
# File 'lib/moneta/adapters/tokyo_cabinet.rb', line 21

def [](key)
  deserialize(@cache[key_for(key)])
end

#clearObject



42
43
44
# File 'lib/moneta/adapters/tokyo_cabinet.rb', line 42

def clear(*)
  @cache.clear
end

#closeObject



46
47
48
# File 'lib/moneta/adapters/tokyo_cabinet.rb', line 46

def close
  @cache.close
end

#delete(key) ⇒ Object



33
34
35
36
37
38
39
40
# File 'lib/moneta/adapters/tokyo_cabinet.rb', line 33

def delete(key, *)
  value = self[key]

  if value
    @cache.delete(key_for(key))
    value
  end
end

#key?(key) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/moneta/adapters/tokyo_cabinet.rb', line 29

def key?(key, *)
  !!self[key]
end

#store(key, value) ⇒ Object



25
26
27
# File 'lib/moneta/adapters/tokyo_cabinet.rb', line 25

def store(key, value, *)
  @cache[key_for(key)] = serialize(value)
end