aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/cache
diff options
context:
space:
mode:
authorJoshua Peek <josh@joshpeek.com>2008-08-06 14:50:02 -0500
committerJoshua Peek <josh@joshpeek.com>2008-08-06 14:54:18 -0500
commite5b1ab7cc39ff57f9789ffda75fb33f72187775d (patch)
treedd161b502ccfaca2e408779107d37386aa368103 /activesupport/lib/active_support/cache
parent73056500f88d569fa497d846dfe6b501a9e03739 (diff)
downloadrails-e5b1ab7cc39ff57f9789ffda75fb33f72187775d.tar.gz
rails-e5b1ab7cc39ff57f9789ffda75fb33f72187775d.tar.bz2
rails-e5b1ab7cc39ff57f9789ffda75fb33f72187775d.zip
MemoryStore is the only "unsafe" store. Make it threadsafe by default.
Diffstat (limited to 'activesupport/lib/active_support/cache')
-rw-r--r--activesupport/lib/active_support/cache/memory_store.rb55
1 files changed, 43 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..9332d50f24 100644
--- a/activesupport/lib/active_support/cache/memory_store.rb
+++ b/activesupport/lib/active_support/cache/memory_store.rb
@@ -3,36 +3,67 @@ module ActiveSupport
class MemoryStore < Store
def initialize
@data = {}
+ @mutex = Mutex.new
+ end
+
+ def fetch(key, options = {})
+ @mutex.synchronize do
+ super
+ end
end
def read(name, options = nil)
- super
- @data[name]
+ @mutex.synchronize do
+ super
+ @data[name]
+ end
end
def write(name, value, options = nil)
- super
- @data[name] = value
+ @mutex.synchronize do
+ super
+ @data[name] = value
+ end
end
def delete(name, options = nil)
- super
- @data.delete(name)
+ @mutex.synchronize do
+ super
+ @data.delete(name)
+ end
end
def delete_matched(matcher, options = nil)
- super
- @data.delete_if { |k,v| k =~ matcher }
+ @mutex.synchronize do
+ super
+ @data.delete_if { |k,v| k =~ matcher }
+ end
end
def exist?(name,options = nil)
- super
- @data.has_key?(name)
+ @mutex.synchronize do
+ super
+ @data.has_key?(name)
+ end
+ end
+
+ def increment(key, amount = 1)
+ @mutex.synchronize do
+ super
+ end
+ end
+
+ def decrement(key, amount = 1)
+ @mutex.synchronize do
+ super
+ end
end
def clear
- @data.clear
+ @mutex.synchronize do
+ @data.clear
+ end
end
end
end
-end \ No newline at end of file
+end