Class: ActiveSupport::Cache::TokyoStore

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

Instance Method Summary collapse

Constructor Details

#initialize(host = '127.0.0.1', port = 1978) ⇒ TokyoStore

Returns a new instance of TokyoStore.



18
19
20
21
22
23
24
25
# File 'lib/active_support/cache/tokyo_store.rb', line 18

def initialize(host = '127.0.0.1', port = 1978)
  super()
  @data = if Object.const_defined?(:TokyoTyrant)
    TokyoTyrant::DB.new(host, port)
  else        
    Rufus::Tokyo::Tyrant.new(host, port)
  end
end

Instance Method Details

#clearObject



56
57
58
59
# File 'lib/active_support/cache/tokyo_store.rb', line 56

def clear
  log("clear", @data.keys.size, nil)
  @data.clear
end

#delete(key, options = nil) ⇒ Object



41
42
43
44
# File 'lib/active_support/cache/tokyo_store.rb', line 41

def delete(key, options = nil)
  super
  @data.delete(key)
end

#delete_matched(matcher, options = nil) ⇒ Object



46
47
48
49
# File 'lib/active_support/cache/tokyo_store.rb', line 46

def delete_matched(matcher, options = nil)
  super
  @data.keys.each { |k| @data.delete(k) if k =~ matcher }
end

#exist?(key, options = nil) ⇒ Boolean

Returns:

  • (Boolean)


51
52
53
54
# File 'lib/active_support/cache/tokyo_store.rb', line 51

def exist?(key, options = nil)
  super
  not @data[key].nil?
end

#keysObject



61
62
63
# File 'lib/active_support/cache/tokyo_store.rb', line 61

def keys
  @data.keys
end

#read(key, options = nil) ⇒ Object



27
28
29
30
31
32
# File 'lib/active_support/cache/tokyo_store.rb', line 27

def read(key, options = nil)
  super
  @data[key]
rescue 
  nil
end

#write(key, value, options = nil) ⇒ Object



34
35
36
37
38
39
# File 'lib/active_support/cache/tokyo_store.rb', line 34

def write(key, value, options = nil)
  super
  @data[key] = value
rescue 
  nil
end