Class: Rack::MonetaStore

### Home Classes Methods

### In Files

- lib/rack/moneta_store.rb

### Parent

Object

### Methods

- ::new
- #call

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

# Rack::MonetaStore

A Rack middleware that inserts a Moneta store in the environment and supports per-request caching via the the option `:cache => true`.

@example config.ru

    # Add Rack::MonetaStore somewhere in your rack stack
    use Rack::MonetaStore, :Memory, :cache => true

    run lambda { |env|
      env['rack.moneta_store'] # is a Moneta store with per-request caching
    }

@example config.ru

    # Pass it a block like the one passed to Moneta.build
    use Rack::MonetaStore do
      use :Transformer, :value => :zlib
      adapter :Cookie
    end

    run lambda { |env|
      env['rack.moneta_store'] # is a Moneta store without caching
    }

@api public

### Public Class Methods

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

    # File lib/rack/moneta_store.rb, line 28
    def initialize(app, store = nil, options = {}, &block)
      @app = app
      @cache = options.delete(:cache)
      if block
        raise ArgumentError, 'Use either block or options' unless options.empty?
        @store = ::Moneta.build(&block)
      else
        raise ArgumentError, 'Block or argument store is required' unless @store = store
        @store = ::Moneta.new(@store, options) if Symbol === @store
      end
    end

### Public Instance Methods

call(env) click to toggle source

    # File lib/rack/moneta_store.rb, line 40
    def call(env)
      env['rack.moneta_store'] = @cache ? ::Moneta::Cache.new(:cache => ::Moneta::Adapters::Memory.new, :adapter => @store) : @store
      @app.call(env)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.