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, #delete, #increment, #key?, #load, #store

Methods inherited from Proxy

#clear, #delete, #increment, #key?, #load, #store

Methods inherited from Base

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

Methods included from Mixins::WithOptions

#expires, #prefix, #raw, #with

Constructor Details

#initialize(options = {}, &block) ⇒ Shared

Constructor

Parameters:

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

Options Hash (options):

  • :port (Integer) — default: 9000

    TCP port

  • :host (String)

    Server hostname

  • :file (String)

    Unix socket file name



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

def initialize(options = {}, &block)
  @options = options
  @builder = Builder.new(&block)
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