Class: Moneta::Adapters::TokyoCabinet
- Inherits:
-
Object
- Object
- Moneta::Adapters::TokyoCabinet
- Includes:
- Defaults
- Defined in:
- lib/moneta/adapters/tokyo_cabinet.rb
Instance Method Summary collapse
- #[](key) ⇒ Object
- #clear ⇒ Object
- #close ⇒ Object
- #delete(key) ⇒ Object
-
#initialize(options = {}) ⇒ TokyoCabinet
constructor
A new instance of TokyoCabinet.
- #key?(key) ⇒ Boolean
- #store(key, value) ⇒ Object
Methods included from Defaults
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( = {}) file = [: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 |
#clear ⇒ Object
42 43 44 |
# File 'lib/moneta/adapters/tokyo_cabinet.rb', line 42 def clear(*) @cache.clear end |
#close ⇒ Object
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
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 |