Class: ActiveSupport::Cache::AerospikeStore

Inherits:
Store
  • Object
show all
Defined in:
lib/active_support/cache/aerospike_store.rb

Constant Summary collapse

DEFAULT_OPTIONS =
{
    ns: 'test',
    set: 'rails_cache',
    bin: 'data',
    host: '127.0.0.1',
    port: 3000,
    timeout: 0.1,
    ttl: 60,
    unless_exist: false
}

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ AerospikeStore

Returns a new instance of AerospikeStore.



17
18
19
20
21
# File 'lib/active_support/cache/aerospike_store.rb', line 17

def initialize(options = {})
  options.merge!(DEFAULT_OPTIONS) { |_, user, _| user }
  @client = Aerospike::Client.new(options.delete(:host), options.delete(:port), options.dup)
  super
end

Instance Method Details

#clear(options = nil) ⇒ Object



23
24
25
26
27
# File 'lib/active_support/cache/aerospike_store.rb', line 23

def clear(options = nil)
  @client.query(Aerospike::Statement.new(@options[:ns], @options[:set])).each do |entry|
    @client.delete(entry.key)
  end
end

#decrement(name, amount = 1, options = nil) ⇒ Object



36
37
38
39
40
41
# File 'lib/active_support/cache/aerospike_store.rb', line 36

def decrement(name, amount = 1, options = nil)
  options = merged_options(options)
  instrument(:decrement, name, amount: amount) do
    @client.add(key_from(namespaced_key(name, options), options), Aerospike::Bin.new(@options[:bin], (amount * -1)))
  end
end

#increment(name, amount = 1, options = nil) ⇒ Object



29
30
31
32
33
34
# File 'lib/active_support/cache/aerospike_store.rb', line 29

def increment(name, amount = 1, options = nil)
  options = merged_options(options)
  instrument(:increment, name, amount: amount) do
    @client.add(key_from(namespaced_key(name, options), options), Aerospike::Bin.new(@options[:bin], amount))
  end
end