Froze rails gems
[depot.git] / vendor / rails / activesupport / lib / active_support / cache / memory_store.rb
1 module ActiveSupport
2 module Cache
3 # A cache store implementation which stores everything into memory in the
4 # same process. If you're running multiple Ruby on Rails server processes
5 # (which is the case if you're using mongrel_cluster or Phusion Passenger),
6 # then this means that your Rails server process instances won't be able
7 # to share cache data with each other. If your application never performs
8 # manual cache item expiry (e.g. when you're using generational cache keys),
9 # then using MemoryStore is ok. Otherwise, consider carefully whether you
10 # should be using this cache store.
11 #
12 # MemoryStore is not only able to store strings, but also arbitrary Ruby
13 # objects.
14 #
15 # MemoryStore is not thread-safe. Use SynchronizedMemoryStore instead
16 # if you need thread-safety.
17 class MemoryStore < Store
18 def initialize
19 @data = {}
20 end
21
22 def read(name, options = nil)
23 super
24 @data[name]
25 end
26
27 def write(name, value, options = nil)
28 super
29 @data[name] = value.freeze
30 end
31
32 def delete(name, options = nil)
33 super
34 @data.delete(name)
35 end
36
37 def delete_matched(matcher, options = nil)
38 super
39 @data.delete_if { |k,v| k =~ matcher }
40 end
41
42 def exist?(name,options = nil)
43 super
44 @data.has_key?(name)
45 end
46
47 def clear
48 @data.clear
49 end
50 end
51 end
52 end