Class: ActiveSupport::Cache::EhcacheStore

Inherits:
Store
  • Object
show all
Includes:
Ehcache::Rails
Defined in:
lib/active_support/cache/ehcache_store.rb

Overview

Rails 3 cache store implementation which stores data in Ehcache: http://www.ehcache.org/

Constant Summary

Constants included from Ehcache::Rails

Ehcache::Rails::DEFAULT_RAILS_CACHE_NAME, Ehcache::Rails::RAILS_CONFIG_DIR

Instance Method Summary collapse

Methods included from Ehcache::Rails

#create_cache, #create_cache_manager

Constructor Details

#initialize(*args) ⇒ EhcacheStore

Returns a new instance of EhcacheStore.



11
12
13
14
15
16
17
# File 'lib/active_support/cache/ehcache_store.rb', line 11

def initialize(*args)
  args = args.flatten
  options = args.extract_options!
  super(*options)
  @ehcache = self.create_cache   # This comes from the Ehcache::Rails mixin.
  extend Strategy::LocalCache
end

Instance Method Details

#clear(options = nil) ⇒ Object



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

def clear(options = nil)
  @ehcache.remove_all
end

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

:nodoc:



25
26
27
28
29
# File 'lib/active_support/cache/ehcache_store.rb', line 25

def decrement(name, amount = 1, options = nil) # :nodoc:
  @ehcache.compare_and_swap(name) { |current_value|
    current_value - amount
  }
end

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

:nodoc:



19
20
21
22
23
# File 'lib/active_support/cache/ehcache_store.rb', line 19

def increment(name, amount = 1, options = nil) # :nodoc:
  @ehcache.compare_and_swap(name) { |current_value|
    current_value + amount
  }
end

#statsObject



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

def stats
  @ehcache.statistics
end