Class: ActiveSupport::Cache::TorqueBoxStore
- Inherits:
-
Store
- Object
- Store
- ActiveSupport::Cache::TorqueBoxStore
- Defined in:
- lib/active_support/cache/torque_box_store.rb
Constant Summary collapse
- SECONDS =
java.util.concurrent.TimeUnit::SECONDS
Instance Method Summary collapse
-
#cleanup(options = nil) ⇒ Object
Cleanup the cache by removing expired entries.
-
#clear(options = nil) ⇒ Object
Clear the entire cache.
- #clustering_mode ⇒ Object
-
#decrement(name, amount = 1, options = nil) ⇒ Object
Decrement an integer value in the cache; return new value.
-
#delete_matched(matcher, options = nil) ⇒ Object
Delete all entries with keys matching the pattern.
-
#increment(name, amount = 1, options = nil) ⇒ Object
Increment an integer value in the cache; return new value.
-
#initialize(options = {}) ⇒ TorqueBoxStore
constructor
A new instance of TorqueBoxStore.
- #name ⇒ Object
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( = {}) super() 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( = nil) = () keys.each do |key| entry = read_entry(key, ) delete_entry(key, ) 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( = nil) cache.clearAsync end |
#clustering_mode ⇒ Object
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? [:mode] distributed = [:d, :dist, :distributed, :distribution].include? [:mode] sync = !![: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, = nil) increment( name, -amount, ) 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, = nil ) = () pattern = key_matcher( matcher, ) keys.each { |key| delete( key, ) 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, = nil) = ( ) key = namespaced_key( name, ) current = cache.get(key) value = decode(current).value.to_i new_entry = Entry.new( value+amount, ) if cache.replace( key, current, encode(new_entry) ) return new_entry.value else raise "Concurrent modification, old value was #{value}" end end |
#name ⇒ Object
16 17 18 |
# File 'lib/active_support/cache/torque_box_store.rb', line 16 def name [:name] || TORQUEBOX_APP_NAME end |