Class: Riak::CacheStore

Inherits:
ActiveSupport::Cache::Store
  • Object
show all
Defined in:
lib/riak/cache_store.rb

Overview

An ActiveSupport::Cache::Store implementation that uses Riak. Compatible only with ActiveSupport version 3 or greater.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ CacheStore

Creates a Riak-backed cache store.



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/riak/cache_store.rb', line 13

def initialize(options = {})
  super
  @bucket_name = options.delete(:bucket) || '_cache'
  @n_value = options.delete(:n_value) || 2
  @r = options.delete(:r) || 1
  @w = options.delete(:w) || 1
  @dw = options.delete(:dw) || 0
  @rw = options.delete(:rw) || "quorum"
  @client = Riak::Client.new(options)
  set_bucket_defaults
end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



10
11
12
# File 'lib/riak/cache_store.rb', line 10

def client
  @client
end

Instance Method Details

#bucketObject



25
26
27
# File 'lib/riak/cache_store.rb', line 25

def bucket
  @bucket ||= @client.bucket(@bucket_name)
end

#delete_matched(matcher, options = {}) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'lib/riak/cache_store.rb', line 29

def delete_matched(matcher, options={})
  instrument(:delete_matched, matcher) do
    bucket.keys do |keys|
      keys.grep(matcher).each do |k|
        bucket.delete(k)
      end
    end
  end
end