Class: ActiveSupport::Cache::TorqueBoxStore

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

Constant Summary

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

Instance Method Summary (collapse)

Constructor Details

- (TorqueBoxStore) initialize(options = {})

Returns a new instance of TorqueBoxStore



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

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

Instance Method Details

- (Object) cache



117
118
119
# File 'cache/lib/active_support/cache/torque_box_store.rb', line 117

def cache
  @cache ||= TorqueBox::Infinispan::Cache.new( defaults.merge(options) )
end

- (Object) cleanup(options = nil)



79
80
81
82
83
84
85
# File 'cache/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

- (Object) clear(options = nil)



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

def clear(options = nil)
  cache.clear
end

- (Object) clustering_mode



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

def clustering_mode
  cache.clustering_mode
end

- (Object) decrement(name, amount = 1, options = nil)



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

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

- (Object) defaults



89
90
91
# File 'cache/lib/active_support/cache/torque_box_store.rb', line 89

def defaults
  {:name=>'__torque_box_store__', :mode => :invalidation, :sync => false}
end

- (Object) delete_entry(key, options)



110
111
112
# File 'cache/lib/active_support/cache/torque_box_store.rb', line 110

def delete_entry(key, options) # :nodoc:
  cache.remove( key ) && true
end

- (Object) delete_matched(matcher, options = nil)



50
51
52
53
54
# File 'cache/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

- (Object) increment(name, amount = 1, options = nil)



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'cache/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

- (Object) keys



94
95
96
# File 'cache/lib/active_support/cache/torque_box_store.rb', line 94

def keys
  cache.keys
end

- (Object) name



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

def name
  options[:name] || TORQUEBOX_APP_NAME
end

- (Object) read_entry(key, options)



99
100
101
# File 'cache/lib/active_support/cache/torque_box_store.rb', line 99

def read_entry(key, options)
  cache.get( key )
end

- (Object) write_entry(key, entry, options = {})



104
105
106
107
# File 'cache/lib/active_support/cache/torque_box_store.rb', line 104

def write_entry(key, entry, options = {})
  previous_value = options[:unless_exist] ? cache.put_if_absent( key, entry ) : cache.put( key, entry )
  previous_value unless previous_value.nil?
end