Class: Moneta::Adapters::Cassandra

### Home Classes Methods

### In Files

- lib/moneta/adapters/cassandra.rb

### Parent

Object

### Methods

- ::new
- #clear
- #close
- #delete
- #key?
- #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::MongoBase
- Moneta::Adapters::MongoMoped
- Moneta::Adapters::MongoOfficial
- 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::Cassandra

Cassandra backend @api public @author Potapov Sergey (aka Blake)

### Attributes

backend[R]

### Public Class Methods

new(options = {}) click to toggle source

@param [Hash] options @option options [String] :keyspace ('moneta') Cassandra keyspace @option options [String] :column_family ('moneta') Cassandra column family @option options [String] :host ('127.0.0.1') Server host name @option options [Integer] :port (9160) Server port @option options [Integer] :expires Default expiration time @option options [::Cassandra] :backend Use existing backend instance @option options Other options passed to `Cassandra#new`

    # File lib/moneta/adapters/cassandra.rb, line 22
    def initialize(options = {})
      self.default_expires = options.delete(:expires)
      @cf = (options.delete(:column_family) || 'moneta').to_sym
      if options[:backend]
        @backend = options[:backend]
      else
        keyspace = options.delete(:keyspace) || 'moneta'
        options[:retries] ||= 3
        options[:connect_timeout] ||= 10
        options[:timeout] ||= 10
        @backend = ::Cassandra.new('system',
                                   "#{options[:host] || '127.0.0.1'}:#{options[:port] || 9160}",
                                   options)
        unless @backend.keyspaces.include?(keyspace)
          cf_def = ::Cassandra::ColumnFamily.new(keyspace: keyspace, name: @cf.to_s)
          ks_def = ::Cassandra::Keyspace.new(name: keyspace,
                                             strategy_class: 'SimpleStrategy',
                                             strategy_options: { 'replication_factor' => '1' },
                                             replication_factor: 1,
                                             cf_defs: [cf_def])
          # Wait for keyspace to be created (issue #24)
          10.times do
            begin
              @backend.add_keyspace(ks_def)
            rescue Exception => ex
              warn "Moneta::Adapters::Cassandra - #{ex.message}"
            end
            break if @backend.keyspaces.include?(keyspace)
            sleep 0.1
          end
        end
        @backend.keyspace = keyspace
      end
    end

### Public Instance Methods

clear(options = {}) click to toggle source

(see Proxy#clear)

    # File lib/moneta/adapters/cassandra.rb, line 91
    def clear(options = {})
      @backend.clear_column_family!(@cf)
      self
    end

close() click to toggle source

(see Proxy#close)

    # File lib/moneta/adapters/cassandra.rb, line 97
    def close
      @backend.disconnect!
      nil
    end

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

(see Proxy#delete)

    # File lib/moneta/adapters/cassandra.rb, line 83
    def delete(key, options = {})
      if value = load(key, options)
        @backend.remove(@cf, key)
        value
      end
    end

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

(see Proxy#key?)

    # File lib/moneta/adapters/cassandra.rb, line 58
    def key?(key, options = {})
      if @backend.exists?(@cf, key)
        load(key, options) if options.include?(:expires)
        true
      else
        false
      end
    end

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

(see Proxy#load)

    # File lib/moneta/adapters/cassandra.rb, line 68
    def load(key, options = {})
      if value = @backend.get(@cf, key)
        expires = expires_value(options, nil)
        @backend.insert(@cf, key, {'value' => value['value'] }, ttl: expires || nil) if expires != nil
        value['value']
      end
    end

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

(see Proxy#store)

    # File lib/moneta/adapters/cassandra.rb, line 77
    def store(key, value, options = {})
      @backend.insert(@cf, key, {'value' => value}, ttl: expires_value(options) || nil)
      value
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.