A cache store implementation which stores everything into memory in the same process. If you‘re running multiple Ruby on Rails server processes (which is the case if you‘re using mongrel_cluster or Phusion Passenger), then this means that your Rails server process instances won‘t be able to share cache data with each other. If your application never performs manual cache item expiry (e.g. when you‘re using generational cache keys), then using MemoryStore is ok. Otherwise, consider carefully whether you should be using this cache store.
MemoryStore is not only able to store strings, but also arbitrary Ruby objects.
MemoryStore is not thread-safe. Use SynchronizedMemoryStore instead if you need thread-safety.
[ show source ]
# File activesupport/lib/active_support/cache/memory_store.rb, line 18 18: def initialize 19: @data = {} 20: end
[ show source ]
# File activesupport/lib/active_support/cache/memory_store.rb, line 53 53: def clear 54: @data.clear 55: end
[ show source ]
# File activesupport/lib/active_support/cache/memory_store.rb, line 38 38: def delete(name, options = nil) 39: super 40: @data.delete(name) 41: end
[ show source ]
# File activesupport/lib/active_support/cache/memory_store.rb, line 43 43: def delete_matched(matcher, options = nil) 44: super 45: @data.delete_if { |k,v| k =~ matcher } 46: end
[ show source ]
# File activesupport/lib/active_support/cache/memory_store.rb, line 48 48: def exist?(name, options = nil) 49: super 50: @data.has_key?(name) 51: end
[ show source ]
# File activesupport/lib/active_support/cache/memory_store.rb, line 28 28: def read(name, options = nil) 29: super 30: @data[name] 31: end
[ show source ]
# File activesupport/lib/active_support/cache/memory_store.rb, line 22 22: def read_multi(*names) 23: results = {} 24: names.each { |n| results[n] = read(n) } 25: results 26: end
[ show source ]
# File activesupport/lib/active_support/cache/memory_store.rb, line 33 33: def write(name, value, options = nil) 34: super 35: @data[name] = value.freeze 36: end