Class: Moneta::Shared

Inherits:
Wrapper show all
Defined in:
lib/moneta/shared.rb

Overview

Shares a store between processes

Examples:

Share a store

Moneta.build do
  use :Transformer, key: :marshal, value: :marshal
  use :Shared do
    adapter :GDBM, file: 'shared.db'
  end
end

Instance Attribute Summary

Attributes inherited from Proxy

#adapter

Instance Method Summary collapse

Methods inherited from Wrapper

#clear, #config, #create, #delete, #each_key, #features, #fetch_values, #increment, #key?, #load, #merge!, #slice, #store, #values_at

Methods inherited from Proxy

#clear, #config, #create, #delete, #each_key, #features, features_mask, #fetch_values, #increment, #key?, #load, #merge!, not_supports, #slice, #store, #values_at

Methods included from Config

#config, included

Methods included from Defaults

#[], #[]=, #create, #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 = {}, &block) ⇒ Shared

Returns a new instance of Shared.

Parameters:

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

Options Hash (options):

  • :port (Integer) — default: 9000

    TCP port

  • :host (String)

    Server hostname

  • :socket (String)

    Unix socket file name



18
19
20
21
22
# File 'lib/moneta/shared.rb', line 18

def initialize(options = {}, &block)
  @options = options
  @builder = Builder.new(&block)
  @connect_lock = ::Mutex.new
end

Instance Method Details

#closeObject



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/moneta/shared.rb', line 25

def close
  if server?
    @server.stop
    @thread.join
    @server = @thread = nil
  end
  if @adapter
    @adapter.close
    @adapter = nil
  end
end

#server?Boolean

Returns true if this wrapper is running as the server

Returns:

  • (Boolean)

    wrapper is a server



40
41
42
# File 'lib/moneta/shared.rb', line 40

def server?
  @server != nil
end