Class: ActiveSupport::Cache::TorqueBoxStore

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

Constant Summary collapse

SECONDS =
java.util.concurrent.TimeUnit::SECONDS

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ TorqueBoxStore

Returns a new instance of TorqueBoxStore.



30
31
32
33
# File 'lib/active_support/cache/torque_box_store.rb', line 30

def initialize(options = {})
  super(options)
  cache
end

Instance Method Details

#cleanup(options = nil) ⇒ Object

Cleanup the cache by removing expired entries.



79
80
81
82
83
84
85
# File 'lib/active_support/cache/torque_box_store.rb', line 79

def cleanup(options = nil)
  options = merged_options(options)
  keys.each do |key|
    entry = read_entry(key, options)
    delete_entry(key, options) if entry && entry.expired?
  end
end

#clear(options = nil) ⇒ Object

Clear the entire cache. Be careful with this method since it could affect other processes if shared cache is being used.



45
46
47
# File 'lib/active_support/cache/torque_box_store.rb', line 45

def clear(options = nil)
  cache.clear
end

#clustering_modeObject



39
40
41
# File 'lib/active_support/cache/torque_box_store.rb', line 39

def clustering_mode
  cache.clustering_mode
end

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

Decrement an integer value in the cache; return new value



74
75
76
# File 'lib/active_support/cache/torque_box_store.rb', line 74

def decrement(name, amount = 1, options = nil)
  increment( name, -amount, options )
end

#delete_matched(matcher, options = nil) ⇒ Object

Delete all entries with keys matching the pattern.



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

def delete_matched( matcher, options = nil )
  options = merged_options(options)
  pattern = key_matcher( matcher, options )
  keys.each { |key| delete( key, options ) if key =~ pattern }
end

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

Increment an integer value in the cache; return new value



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/active_support/cache/torque_box_store.rb', line 57

def increment(name, amount = 1, options = nil)
  options = merged_options( options )

  # Get the current entry
  key = namespaced_key( name, options )
  current = read_entry(key, options)
  value = current.value.to_i

  new_entry = Entry.new( value+amount, options )
  if cache.replace(key, current, new_entry)
    return new_entry.value
  else
    raise "Concurrent modification, old value was #{value}"
  end
end

#nameObject



35
36
37
# File 'lib/active_support/cache/torque_box_store.rb', line 35

def name
  options[:name] || TORQUEBOX_APP_NAME
end