Class: Moneta::Adapters::LevelDB

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

Overview

LevelDB backend

Instance Method Summary collapse

Methods included from IncrementSupport

#increment

Methods included from HashAdapter

#delete, #load, #store

Methods included from Defaults

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

Methods included from OptionSupport

#expires, #prefix, #raw, #with

Constructor Details

#initialize(options = {}) ⇒ LevelDB

Returns a new instance of LevelDB

Options Hash (options):

  • :dir (String)
    • Database path

  • All (Object)

    other options passed to `LevelDB::DB#new`

Raises:

  • (ArgumentError)

11
12
13
14
# File 'lib/moneta/adapters/leveldb.rb', line 11

def initialize(options = {})
  raise ArgumentError, 'Option :dir is required' unless options[:dir]
  @hash = ::LevelDB::DB.new(options[:dir])
end

Instance Method Details

#clear(options = {}) ⇒ void

This method returns an undefined value.

Clear all keys in this store


22
23
24
25
# File 'lib/moneta/adapters/leveldb.rb', line 22

def clear(options = {})
  @hash.each {|k,v| delete(k, options) }
  self
end

#closeObject

Explicitly close the store


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

def close
  @hash.close
  nil
end

#key?(key, options = {}) ⇒ Boolean

Exists the value with key

Options Hash (options):

  • :expires (Integer)

    Update expiration time (See `Moneta::Expires`)

  • :prefix (String)

    Prefix key (See `Moneta::Transformer`)

  • Other (Object)

    options as defined by the adapters or middleware


17
18
19
# File 'lib/moneta/adapters/leveldb.rb', line 17

def key?(key, options = {})
  @hash.includes?(key)
end