diff options
Diffstat (limited to 'activesupport/lib/active_support/cache/memory_store.rb')
-rw-r--r-- | activesupport/lib/active_support/cache/memory_store.rb | 52 |
1 files changed, 40 insertions, 12 deletions
diff --git a/activesupport/lib/active_support/cache/memory_store.rb b/activesupport/lib/active_support/cache/memory_store.rb index 6f114273e4..f3e4b8c13b 100644 --- a/activesupport/lib/active_support/cache/memory_store.rb +++ b/activesupport/lib/active_support/cache/memory_store.rb @@ -3,36 +3,64 @@ module ActiveSupport 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) - super - @data[name] + @guard.synchronize do + super + @data[name] + end end def write(name, value, options = nil) - super - @data[name] = value + @guard.synchronize do + super + @data[name] = value.freeze + end end def delete(name, options = nil) - super - @data.delete(name) + @guard.synchronize do + @data.delete(name) + end end def delete_matched(matcher, options = nil) - super - @data.delete_if { |k,v| k =~ matcher } + @guard.synchronize do + @data.delete_if { |k,v| k =~ matcher } + end end def exist?(name,options = nil) - super - @data.has_key?(name) + @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 - @data.clear + @guard.synchronize do + @data.clear + end end end end -end
\ No newline at end of file +end |