Class: ActiveSupport::Cache::MemoryStore
- Inherits:
-
Store
show all
- Defined in:
- lib/gems/activesupport-2.2.2/lib/active_support/cache/memory_store.rb
Overview
A cache store implementation which stores everything into memory in the same process. If you’re running multiple Ruby on Rails server processes (which is the case if you’re using mongrel_cluster or Phusion Passenger), then this means that your Rails server process instances won’t be able to share cache data with each other. If your application never performs manual cache item expiry (e.g. when you’re using generational cache keys), then using MemoryStore is ok. Otherwise, consider carefully whether you should be using this cache store.
MemoryStore is not only able to store strings, but also arbitrary Ruby objects.
MemoryStore is not thread-safe. Use SynchronizedMemoryStore instead if you need thread-safety.
Instance Method Summary
collapse
Methods inherited from Store
#decrement, #fetch, #increment, #silence!
Constructor Details
Returns a new instance of MemoryStore.
18
19
20
|
# File 'lib/gems/activesupport-2.2.2/lib/active_support/cache/memory_store.rb', line 18
def initialize
@data = {}
end
|
Instance Method Details
47
48
49
|
# File 'lib/gems/activesupport-2.2.2/lib/active_support/cache/memory_store.rb', line 47
def clear
@data.clear
end
|
#delete(name, options = nil) ⇒ Object
32
33
34
35
|
# File 'lib/gems/activesupport-2.2.2/lib/active_support/cache/memory_store.rb', line 32
def delete(name, options = nil)
super
@data.delete(name)
end
|
#delete_matched(matcher, options = nil) ⇒ Object
37
38
39
40
|
# File 'lib/gems/activesupport-2.2.2/lib/active_support/cache/memory_store.rb', line 37
def delete_matched(matcher, options = nil)
super
@data.delete_if { |k,v| k =~ matcher }
end
|
#exist?(name, options = nil) ⇒ Boolean
42
43
44
45
|
# File 'lib/gems/activesupport-2.2.2/lib/active_support/cache/memory_store.rb', line 42
def exist?(name,options = nil)
super
@data.has_key?(name)
end
|
#read(name, options = nil) ⇒ Object
22
23
24
25
|
# File 'lib/gems/activesupport-2.2.2/lib/active_support/cache/memory_store.rb', line 22
def read(name, options = nil)
super
@data[name]
end
|
#write(name, value, options = nil) ⇒ Object
27
28
29
30
|
# File 'lib/gems/activesupport-2.2.2/lib/active_support/cache/memory_store.rb', line 27
def write(name, value, options = nil)
super
@data[name] = value.freeze
end
|