Class: Moneta::Adapters::TDB

Inherits:
Object
  • Object
show all
Includes:
Defaults, EachKeySupport, HashAdapter, IncrementSupport
Defined in:
lib/moneta/adapters/tdb.rb

Overview

TDB backend

Instance Attribute Summary

Attributes included from HashAdapter

#backend

Instance Method Summary collapse

Methods included from EachKeySupport

#each_key, included

Methods included from IncrementSupport

included, #increment

Methods included from HashAdapter

#clear, #delete, #fetch_values, #key?, #load, #merge!, #slice, #store, #values_at

Methods included from Defaults

#[], #[]=, #decrement, #each_key, #features, #fetch, #fetch_values, included, #increment, #key?, #merge!, #slice, #supports?, #update, #values_at

Methods included from OptionSupport

#expires, #prefix, #raw, #with

Constructor Details

#initialize(options) ⇒ TDB

Returns a new instance of TDB.

Parameters:

  • options (Hash)

Options Hash (options):

  • :file (String)

    Database file

  • :backend (::TDB)

    Use existing backend instance



18
19
20
21
22
23
24
# File 'lib/moneta/adapters/tdb.rb', line 18

def initialize(options)
  @backend = options[:backend] ||
    begin
      raise ArgumentError, 'Option :file is required' unless file = options.delete(:file)
      ::TDB.new(file, options)
    end
end

Instance Method Details

#closeObject

Explicitly close the store

Returns:

  • nil



27
28
29
30
# File 'lib/moneta/adapters/tdb.rb', line 27

def close
  @backend.close
  nil
end

#create(key, value, options = {}) ⇒ Boolean

Note:

Not every Moneta store implements this method, a NotImplementedError is raised if it is not supported.

Atomically sets a key to value if it’s not set.

Parameters:

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

Options Hash (options):

  • :expires (Integer)

    Update expiration time (See Expires)

  • :raw (Boolean)

    Raw access without value transformation (See Transformer)

  • :prefix (String)

    Prefix key (See Transformer)

Returns:

  • (Boolean)

    key was set



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

def create(key, value, options = {})
  @backend.insert!(key, value)
  true
rescue ::TDB::ERR::EXISTS
  false
end