class ActiveSupport::Cache::AerospikeStore

Constants

AEROSPIKE_DEFAULT_OPTIONS

Public Class Methods

new(options = {}) click to toggle source
Calls superclass method
# File lib/active_support/cache/aerospike_store.rb, line 16
def initialize(options = {})
  options.merge!(self.class::AEROSPIKE_DEFAULT_OPTIONS) { |key, v1, v2| v1 }
  @client = options.delete(:client) || Aerospike::Client.new(options.delete(:host), options.delete(:port))
  super
end

Public Instance Methods

decrement(name, amount = 1, options = nil) click to toggle source
# File lib/active_support/cache/aerospike_store.rb, line 30
def decrement(name, amount = 1, options = nil)
  options = merged_options(options)
  instrument(:decrement, name, :amount => amount) do
    key = namespaced_key(name, options)
    @client.add(as_key(key, options), {options[:bin] => -1 * amount}, options)
  end
end
increment(name, amount = 1, options = nil) click to toggle source
# File lib/active_support/cache/aerospike_store.rb, line 22
def increment(name, amount = 1, options = nil)
  options = merged_options(options)
  instrument(:increment, name, :amount => amount) do
    key = namespaced_key(name, options)
    @client.add(as_key(key, options), {options[:bin] => amount}, options)
  end
end

Protected Instance Methods

delete_entry(key, options) click to toggle source
# File lib/active_support/cache/aerospike_store.rb, line 70
def delete_entry(key, options)
  @client.delete(as_key(key, options))
end
internal_read_entry(key, options) click to toggle source
# File lib/active_support/cache/aerospike_store.rb, line 39
def internal_read_entry(key, options)
  record = @client.get(as_key(key, options))
  if record 
    # single-bin namespaces do not return a bin name
    (record.bins.length == 1)? record.bins.values.first : record.bins[options[:bin]]
  else
    nil
  end
end
read_entry(key, options) click to toggle source
# File lib/active_support/cache/aerospike_store.rb, line 49
def read_entry(key, options)
  if value = internal_read_entry(key, options)
    # if it is not raw it is a marshalled ActiveSupport::Cache::Entry
    value = options[:raw]? ActiveSupport::Cache::Entry.new(value) : Marshal.load(value)
  else
    nil
  end
end
write_entry(key, entry, options) click to toggle source
# File lib/active_support/cache/aerospike_store.rb, line 58
def write_entry(key, entry, options)
  options[:expiration] ||= options[:expires_in] if options[:expires_in]
  options[:record_exists_action] ||= options[:unless_exist]? Aerospike::RecordExistsAction::CREATE_ONLY : Aerospike::RecordExistsAction::REPLACE
  value = options[:raw]? entry.value : Marshal.dump(entry)
  begin
    @client.put(as_key(key, options), {options[:bin] => value}, options)
  rescue Aerospike::Exceptions::Aerospike => e
    raise unless (e.result_code == Aerospike::ResultCode::KEY_EXISTS_ERROR)
    false
  end
end

Private Instance Methods

as_key(key, options) click to toggle source
# File lib/active_support/cache/aerospike_store.rb, line 75
def as_key(key, options)
  Aerospike::Key.new(options[:ns], options[:set], key)
end