mirror of
https://github.com/github/rails.git
synced 2026-01-26 23:08:58 -05:00
Removed monitor from MemoryStore and created a seperate threadsafe store called SynchronizedMemoryStore
This commit is contained in:
@@ -3,63 +3,35 @@ 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)
|
||||
@guard.synchronize do
|
||||
super
|
||||
@data[name]
|
||||
end
|
||||
super
|
||||
@data[name]
|
||||
end
|
||||
|
||||
def write(name, value, options = nil)
|
||||
@guard.synchronize do
|
||||
super
|
||||
@data[name] = value.freeze
|
||||
end
|
||||
super
|
||||
@data[name] = value.freeze
|
||||
end
|
||||
|
||||
def delete(name, options = nil)
|
||||
@guard.synchronize do
|
||||
@data.delete(name)
|
||||
end
|
||||
super
|
||||
@data.delete(name)
|
||||
end
|
||||
|
||||
def delete_matched(matcher, options = nil)
|
||||
@guard.synchronize do
|
||||
@data.delete_if { |k,v| k =~ matcher }
|
||||
end
|
||||
super
|
||||
@data.delete_if { |k,v| k =~ matcher }
|
||||
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
|
||||
super
|
||||
@data.has_key?(name)
|
||||
end
|
||||
|
||||
def clear
|
||||
@guard.synchronize do
|
||||
@data.clear
|
||||
end
|
||||
@data.clear
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
46
activesupport/lib/active_support/cache/synchronized_memory_store.rb
vendored
Normal file
46
activesupport/lib/active_support/cache/synchronized_memory_store.rb
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
module ActiveSupport
|
||||
module Cache
|
||||
class SynchronizedMemoryStore < MemoryStore
|
||||
def initialize
|
||||
super
|
||||
@guard = Monitor.new
|
||||
end
|
||||
|
||||
def fetch(key, options = {})
|
||||
@guard.synchronize { super }
|
||||
end
|
||||
|
||||
def read(name, options = nil)
|
||||
@guard.synchronize { super }
|
||||
end
|
||||
|
||||
def write(name, value, options = nil)
|
||||
@guard.synchronize { super }
|
||||
end
|
||||
|
||||
def delete(name, options = nil)
|
||||
@guard.synchronize { super }
|
||||
end
|
||||
|
||||
def delete_matched(matcher, options = nil)
|
||||
@guard.synchronize { super }
|
||||
end
|
||||
|
||||
def exist?(name,options = nil)
|
||||
@guard.synchronize { super }
|
||||
end
|
||||
|
||||
def increment(key, amount = 1)
|
||||
@guard.synchronize { super }
|
||||
end
|
||||
|
||||
def decrement(key, amount = 1)
|
||||
@guard.synchronize { super }
|
||||
end
|
||||
|
||||
def clear
|
||||
@guard.synchronize { super }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user