Parent

Namespace

Included Modules

Files

Class/Module Index [+]

Quicksearch

Moneta::Stack

Combines multiple stores. Reads return the result from the first store, writes go to all stores.

@example Add `Moneta::Stack` to proxy stack

Moneta.build do
  use(:Stack) do
    add { adapter :Redis }
    add { adapter :File, :dir => 'data' }
    add { adapter :File, :dir => 'replicate' }
  end
end

@api public

Attributes

stack[R]

Public Class Methods

new(options = {}, &block) click to toggle source

@param [Hash] options Options hash @option options [Array] :stack Array of Moneta stores @yieldparam Builder block

# File lib/moneta/stack.rb, line 38
def initialize(options = {}, &block)
  @stack = options[:stack].to_a
  DSL.new(@stack, &block) if block_given?
end

Public Instance Methods

clear(options = {}) click to toggle source

(see Proxy#clear)

# File lib/moneta/stack.rb, line 86
def clear(options = {})
  @stack.each {|s| s.clear(options) }
  self
end
close() click to toggle source

(see Proxy#close)

# File lib/moneta/stack.rb, line 92
def close
  @stack.each {|s| s.close }
  nil
end
create(key, value, options = {}) click to toggle source

(see Proxy#create)

# File lib/moneta/stack.rb, line 71
def create(key, value, options = {})
  last = false
  @stack.each {|s| last = s.create(key, value, options) }
  last
end
delete(key, options = {}) click to toggle source

(see Proxy#delete)

# File lib/moneta/stack.rb, line 78
def delete(key, options = {})
  @stack.inject(nil) do |value, s|
    v = s.delete(key, options)
    value || v
  end
end
features() click to toggle source

(see Proxy#features)

# File lib/moneta/stack.rb, line 98
def features
  @features ||=
    begin
      features = @stack.map(&:features)
      features.inject(features.first, &:&).freeze
    end
end
increment(key, amount = 1, options = {}) click to toggle source

(see Proxy#increment)

# File lib/moneta/stack.rb, line 64
def increment(key, amount = 1, options = {})
  last = nil
  @stack.each {|s| last = s.increment(key, amount, options) }
  last
end
key?(key, options = {}) click to toggle source

(see Proxy#key?)

# File lib/moneta/stack.rb, line 44
def key?(key, options = {})
  @stack.any? {|s| s.key?(key, options) }
end
load(key, options = {}) click to toggle source

(see Proxy#load)

# File lib/moneta/stack.rb, line 49
def load(key, options = {})
  @stack.each do |s|
    value = s.load(key, options)
    return value if value != nil
  end
  nil
end
store(key, value, options = {}) click to toggle source

(see Proxy#store)

# File lib/moneta/stack.rb, line 58
def store(key, value, options = {})
  @stack.each {|s| s.store(key, value, options) }
  value
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.