Class: Moneta::Adapters::TokyoCabinet

Inherits:
Memory
  • Object
show all
Defined in:
lib/moneta/adapters/tokyocabinet.rb

Overview

TokyoCabinet backend

Instance Method Summary collapse

Methods included from IncrementSupport

#increment

Methods included from HashAdapter

#clear, #key?, #load, #store

Methods included from Defaults

#[], #[]=, #decrement, #fetch, #increment, #key?

Methods included from OptionSupport

#expires, #prefix, #raw, #with

Constructor Details

#initialize(options = {}) ⇒ TokyoCabinet

Returns a new instance of TokyoCabinet

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :file (String)

    Database file

  • :type (Symbol) — default: :hdb

    Database type (:bdb and :hdb possible)

Raises:

  • (ArgumentError)

11
12
13
14
15
16
17
18
19
20
21
# File 'lib/moneta/adapters/tokyocabinet.rb', line 11

def initialize(options = {})
  file = options[:file]
  raise ArgumentError, 'Option :file is required' unless options[:file]
  if options[:type] == :bdb
    @hash = ::TokyoCabinet::BDB.new
    @hash.open(file, ::TokyoCabinet::BDB::OWRITER | ::TokyoCabinet::BDB::OCREAT)
  else
    @hash = ::TokyoCabinet::HDB.new
    @hash.open(file, ::TokyoCabinet::HDB::OWRITER | ::TokyoCabinet::HDB::OCREAT)
  end or raise @hash.errmsg(@hash.ecode)
end

Instance Method Details

#closeObject

Explicitly close the store

Returns:

  • nil


33
34
35
36
# File 'lib/moneta/adapters/tokyocabinet.rb', line 33

def close
  @hash.close
  nil
end

#delete(key, options = {}) ⇒ Object

Delete the key from the store and return the current value

Parameters:

  • key (Object)
  • options (Hash) (defaults to: {})

Options Hash (options):

  • :raw (Boolean)

    Raw access without value transformation (See `Moneta::Transformer`)

  • :prefix (String)

    Prefix key (See `Moneta::Transformer`)

  • Other (Object)

    options as defined by the adapters or middleware

Returns:

  • (Object)

    current value


24
25
26
27
28
29
30
# File 'lib/moneta/adapters/tokyocabinet.rb', line 24

def delete(key, options = {})
  value = load(key, options)
  if value
    @hash.delete(key)
    value
  end
end