aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/cache/memory_store.rb
blob: a44f8774141be7c14e6bd8a29b09d173e1fa8bbb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
module ActiveSupport
  module Cache
    class MemoryStore < Store
      def initialize
        @data = {}
        @mutex = Mutex.new
      end

      def fetch(key, options = {})
        @mutex.synchronize do
          super
        end
      end

      def read(name, options = nil)
        super
        @data[name]
      end

      def write(name, value, options = nil)
        super
        @data[name] = value
      end

      def delete(name, options = nil)
        @data.delete(name)
      end

      def delete_matched(matcher, options = nil)
        @data.delete_if { |k,v| k =~ matcher }
      end

      def exist?(name,options = nil)
        @data.has_key?(name)
      end

      def increment(key, amount = 1)
        @mutex.synchronize do
          super
        end
      end

      def decrement(key, amount = 1)
        @mutex.synchronize do
          super
        end
      end

      def clear
        @data.clear
      end
    end
  end
end