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.



11
12
13
14
# File 'lib/active_support/cache/torque_box_store.rb', line 11

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

Instance Method Details

#cleanup(options = nil) ⇒ Object

Cleanup the cache by removing expired entries.



68
69
70
71
72
73
74
# File 'lib/active_support/cache/torque_box_store.rb', line 68

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.



37
38
39
# File 'lib/active_support/cache/torque_box_store.rb', line 37

def clear(options = nil)
  cache.clearAsync
end

#clustering_modeObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/active_support/cache/torque_box_store.rb', line 20

def clustering_mode
  java_import org.infinispan.config.Configuration::CacheMode
  replicated =  [:r, :repl, :replicated, :replication].include? options[:mode]
  distributed = [:d, :dist, :distributed, :distribution].include? options[:mode]
  sync = !!options[:sync]
  case
  when replicated 
    sync ? CacheMode::REPL_SYNC : CacheMode::REPL_ASYNC
  when distributed
    sync ? CacheMode::DIST_SYNC : CacheMode::DIST_ASYNC
  else
    sync ? CacheMode::INVALIDATION_SYNC : CacheMode::INVALIDATION_ASYNC
  end
end

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

Decrement an integer value in the cache; return new value



63
64
65
# File 'lib/active_support/cache/torque_box_store.rb', line 63

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.



42
43
44
45
46
# File 'lib/active_support/cache/torque_box_store.rb', line 42

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



49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/active_support/cache/torque_box_store.rb', line 49

def increment(name, amount = 1, options = nil)
  options = merged_options( options )
  key = namespaced_key( name, options )
  current = cache.get(key)
  value = decode(current).value.to_i
  new_entry = Entry.new( value+amount, options )
  if cache.replace( key, current, encode(new_entry) )
    return new_entry.value
  else
    raise "Concurrent modification, old value was #{value}"
  end
end

#nameObject



16
17
18
# File 'lib/active_support/cache/torque_box_store.rb', line 16

def name
  options[:name] || TORQUEBOX_APP_NAME
end