File: active_support/cache/memory_store.rb

Overview
Module Structure
Class Hierarchy
Code

Overview

Module Structure

  module: <Toplevel Module>
  module: ActiveSupport#1
  module: Cache#2
  class: MemoryStore#17
inherits from
  Store ( ActiveSupport::Cache )
has properties
method: initialize #18
method: read_multi / 1 #22
method: read / 2 #28
method: write / 3 #33
method: delete / 2 #38
method: delete_matched / 2 #43
method: exist? / 2 #48
method: clear #53

Class Hierarchy

Code

   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_multi(*names)
  23          results = {}
  24          names.each { |n| results[n] = read(n) }
  25          results
  26        end
  27 
  28        def read(name, options = nil)
  29          super
  30          @data[name]
  31        end
  32 
  33        def write(name, value, options = nil)
  34          super
  35          @data[name] = value.freeze
  36        end
  37 
  38        def delete(name, options = nil)
  39          super
  40          @data.delete(name)
  41        end
  42 
  43        def delete_matched(matcher, options = nil)
  44          super
  45          @data.delete_if { |k,v| k =~ matcher }
  46        end
  47 
  48        def exist?(name, options = nil)
  49          super
  50          @data.has_key?(name)
  51        end
  52 
  53        def clear
  54          @data.clear
  55        end
  56      end
  57    end
  58  end