Class: ActiveSupport::Cache::EhcacheStore

Inherits:
Ehcache::ActiveSupportStore show all
Defined in:
lib/active_support/ehcache_store.rb,
lib/active_support/cache/ehcache_store.rb

Instance Attribute Summary

Attributes inherited from Ehcache::ActiveSupportStore

#cache_manager

Instance Method Summary collapse

Methods inherited from Ehcache::ActiveSupportStore

#create_cache, #create_cache_manager, #default_cache_name

Constructor Details

#initialize(*args) ⇒ EhcacheStore

Returns a new instance of EhcacheStore.



10
11
12
13
# File 'lib/active_support/ehcache_store.rb', line 10

def initialize(options = {})
  super() # Rails 2.3.x Store doesn't take any arguments to initialize
  @ehcache = self.create_cache
end

Instance Method Details

#clear(options = nil) ⇒ Object



50
51
52
53
54
55
56
# File 'lib/active_support/ehcache_store.rb', line 50

def clear
  @ehcache.clear
  true
rescue Exception => e
  logger.error("EhcacheError (#{e}): #{e.message}")
  false
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

#delete(key, options = nil) ⇒ Object



30
31
32
33
34
35
# File 'lib/active_support/ehcache_store.rb', line 30

def delete(key, options = nil)
  @ehcache.remove(key)
rescue Exception => e
  logger.error("EhcacheError (#{e}): #{e.message}")
  false
end

#delete_matched(matcher, options = nil) ⇒ Object



45
46
47
48
# File 'lib/active_support/ehcache_store.rb', line 45

def delete_matched(matcher, options = nil)
  super
  raise "Not supported by Ehcache"
end

#exist?(key, options = nil) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/active_support/ehcache_store.rb', line 41

def exist?(key, options = nil)
  @ehcache.exist?(key)
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

#keysObject



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

def keys
  @ehcache.keys
end

#read(key, options = nil) ⇒ Object



15
16
17
18
19
20
# File 'lib/active_support/ehcache_store.rb', line 15

def read(key, options = nil)
  @ehcache[key]
rescue Ehcache::EhcacheError => e
  logger.error("EhcacheError (#{e}): #{e.message}")
  false
end

#statsObject



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

def stats
  @ehcache.statistics
end

#write(key, value, options = {}) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/active_support/ehcache_store.rb', line 22

def write(key, value, options = {})
  @ehcache.put(key, value, options)
  true
rescue Ehcache::EhcacheError => e
  logger.error("EhcacheError (#{e}): #{e.message}")
  false
end