Class: Moneta::Adapters::MemcachedDalli

### Home Classes Methods

### In Files

- lib/moneta/adapters/memcached/dalli.rb

### Parent

Object

### Methods

- ::new
- #clear
- #close
- #create
- #delete
- #increment
- #load
- #store

### Included Modules

- Moneta::Defaults
- Moneta::ExpiresSupport

### 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::Adapters::MemcachedDalli

Memcached backend (using gem dalli) @api public

### Attributes

backend[R]

### Public Class Methods

new(options = {}) click to toggle source

@param [Hash] options @option options [String] :server ('127.0.0.1:11211') Memcached server @option options [Integer] :expires Default expiration time @option options [::Dalli::Client] :backend Use existing backend instance @option options Other options passed to `Dalli::Client#new`

    # File lib/moneta/adapters/memcached/dalli.rb, line 19
    def initialize(options = {})
      self.default_expires = options.delete(:expires)
      @backend = options[:backend] ||
        begin
          server = options.delete(:server) || '127.0.0.1:11211'
          ::Dalli::Client.new(server, options)
        end
    end

### Public Instance Methods

clear(options = {}) click to toggle source

(see Proxy#clear)

    # File lib/moneta/adapters/memcached/dalli.rb, line 72
    def clear(options = {})
      @backend.flush_all
      self
    end

close() click to toggle source

(see Proxy#close)

    # File lib/moneta/adapters/memcached/dalli.rb, line 83
    def close
      @backend.close
      nil
    end

create(key, value, options = {}) click to toggle source

(see Defaults#create)

    # File lib/moneta/adapters/memcached/dalli.rb, line 78
    def create(key, value, options = {})
      @backend.add(key, value, expires_value(options) || nil, :raw => true)
    end

delete(key, options = {}) click to toggle source

(see Proxy#delete)

    # File lib/moneta/adapters/memcached/dalli.rb, line 45
    def delete(key, options = {})
      value = @backend.get(key)
      @backend.delete(key)
      value
    end

increment(key, amount = 1, options = {}) click to toggle source

(see Proxy#increment)

    # File lib/moneta/adapters/memcached/dalli.rb, line 52
    def increment(key, amount = 1, options = {})
      # FIXME: There is a Dalli bug, load(key) returns a wrong value after increment
      # therefore we set default = nil and create the counter manually
      # See https://github.com/mperham/dalli/issues/309
      result =
        if amount >= 0
          @backend.incr(key, amount, expires_value(options) || nil, nil)
        else
          @backend.decr(key, -amount, expires_value(options) || nil, nil)
        end
      if result
        result
      elsif create(key, amount.to_s, options)
        amount
      else
        increment(key, amount, options)
      end
    end

load(key, options = {}) click to toggle source

(see Proxy#load)

    # File lib/moneta/adapters/memcached/dalli.rb, line 29
    def load(key, options = {})
      value = @backend.get(key)
      if value
        expires = expires_value(options, nil)
        @backend.set(key, value, expires || nil, :raw => true) if expires != nil
        value
      end
    end

store(key, value, options = {}) click to toggle source

(see Proxy#store)

    # File lib/moneta/adapters/memcached/dalli.rb, line 39
    def store(key, value, options = {})
      @backend.set(key, value, expires_value(options) || nil, :raw => true)
      value
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.