Class: Moneta::Stack

### Home Classes Methods

### In Files

- lib/moneta/stack.rb

### Parent

Object

### Namespace

- CLASS Moneta::Stack::DSL

### Methods

- ::new
- #clear
- #close
- #create
- #delete
- #features
- #increment
- #key?
- #load
- #store

### Included Modules

- Moneta::Defaults

### Files

- LICENSE

### Class/Module Index

Quicksearch

- Moneta
- Moneta::Adapters
- Moneta::Adapters::ActiveRecord
- Moneta::Adapters::Cassandra
- Moneta::Adapters::Client
- Moneta::Adapters::Cookie
- Moneta::Adapters::Couch
- Moneta::Adapters::DBM
- Moneta::Adapters::DataMapper
- Moneta::Adapters::DataMapper::Store
- Moneta::Adapters::Daybreak
- Moneta::Adapters::File
- Moneta::Adapters::Fog
- Moneta::Adapters::GDBM
- Moneta::Adapters::HBase
- Moneta::Adapters::KyotoCabinet
- Moneta::Adapters::LMDB
- Moneta::Adapters::LRUHash
- Moneta::Adapters::LRUHash::Entry
- Moneta::Adapters::LevelDB
- Moneta::Adapters::LocalMemCache
- Moneta::Adapters::MemcachedDalli
- Moneta::Adapters::MemcachedNative
- Moneta::Adapters::Memory
- Moneta::Adapters::Mongo
- Moneta::Adapters::Null
- Moneta::Adapters::PStore
- Moneta::Adapters::Redis
- Moneta::Adapters::RestClient
- Moneta::Adapters::Riak
- Moneta::Adapters::SDBM
- Moneta::Adapters::Sequel
- Moneta::Adapters::Sqlite
- Moneta::Adapters::TDB
- Moneta::Adapters::TokyoCabinet
- Moneta::Adapters::TokyoTyrant
- Moneta::Adapters::YAML
- Moneta::Builder
- Moneta::Cache
- Moneta::Cache::DSL
- Moneta::CreateSupport
- Moneta::Defaults
- Moneta::Defaults::ClassMethods
- Moneta::Expires
- Moneta::ExpiresSupport
- Moneta::HashAdapter
- Moneta::IncrementSupport
- Moneta::Lock
- Moneta::Logger
- Moneta::Logger::Format
- Moneta::Mutex
- Moneta::OptionMerger
- Moneta::OptionSupport
- Moneta::Pool
- Moneta::Proxy
- Moneta::Semaphore
- Moneta::Server
- Moneta::Shared
- Moneta::Stack
- Moneta::Stack::DSL
- Moneta::SynchronizePrimitive
- Moneta::Transformer
- Moneta::Transformer::Helper
- Moneta::Utils
- Moneta::WeakCreate
- Moneta::WeakIncrement
- Moneta::Wrapper
- Rack
- Rack::Cache
- Rack::Cache::EntityStore
- Rack::Cache::EntityStore::MONETA
- Rack::Cache::EntityStore::Moneta
- Rack::Cache::MetaStore
- Rack::Cache::MetaStore::MONETA
- Rack::Cache::MetaStore::Moneta
- Rack::Cache::MonetaResolver
- Rack::MonetaCookies
- Rack::MonetaRest
- Rack::MonetaStore
- Rack::Session
- Rack::Session::Moneta
- ActionDispatch
- ActionDispatch::Session
- ActionDispatch::Session::MonetaStore
- ActiveSupport
- ActiveSupport::Cache
- ActiveSupport::Cache::MonetaStore

No matching classes.

# 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.