aboutsummaryrefslogblamecommitdiffstats
path: root/activesupport/lib/active_support/cache/memory_store.rb
blob: 9332d50f24ff2223dd28c50d5a92d7ac99d3bdc3 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12




                             






                                  


                                   



                             


                                           



                             


                                     



                             


                                                



                                                
         

                                    















                                    

         
               


                             
         

       
   
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)
        @mutex.synchronize do
          super
          @data[name]
        end
      end

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

      def delete(name, options = nil)
        @mutex.synchronize do
          super
          @data.delete(name)
        end
      end

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

      def exist?(name,options = nil)
        @mutex.synchronize do
          super
          @data.has_key?(name)
        end
      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
        @mutex.synchronize do
          @data.clear
        end
      end
    end
  end
end