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




                             
                            


                                  
                             

               


                                   



                             


                                           

                             
                                    
           


                                     


                             


                                                


                                                
         

                                    


                              


                                    
                             




                                    
                             

               

         
               


                             
         

       
   
module ActiveSupport
  module Cache
    class MemoryStore < Store
      def initialize
        @data = {}
        @guard = Monitor.new
      end

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

      def read(name, options = nil)
        @guard.synchronize do
          super
          @data[name]
        end
      end

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

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

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

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

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

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

      def clear
        @guard.synchronize do
          @data.clear
        end
      end
    end
  end
end