Permalink
Browse files

Merge branch 'master' of git@github.com:rails/rails

  • Loading branch information...
2 parents 0780563 + 5be5305 commit 5514baf63d6d5e19a84c59a0c2cf74f442daed9c David Heinemeier Hansson committed Apr 29, 2008
@@ -277,9 +277,10 @@ class Base
@@debug_routes = true
cattr_accessor :debug_routes
- # Controls whether the application is thread-safe, so multi-threaded servers like WEBrick know whether to apply a mutex
- # around the performance of each action. Action Pack and Active Record are by default thread-safe, but many applications
- # may not be. Turned off by default.
+ # Indicates to Mongrel or Webrick whether to allow concurrent action
+ # processing. Your controller actions and any other code they call must
+ # also behave well when called from concurrent threads. Turned off by
+ # default.
@@allow_concurrency = false
cattr_accessor :allow_concurrency
@@ -62,9 +62,8 @@ def test_storage
assert_equal d, s.cache.get(session_key)[:test]
assert_equal d, s[:test]
end
- end
-
-
+ end
+
def test_deletion
new_session do |s|
session_key = 'session:' + s.session_id
@@ -423,7 +423,9 @@ def self.reset_subclasses #:nodoc:
@@default_timezone = :local
# Determines whether to use a connection for each thread, or a single shared connection for all threads.
- # Defaults to false. Set to true if you're writing a threaded application.
+ # Defaults to false. If you're writing a threaded application, set to true
+ # and periodically call verify_active_connections! to clear out connections
+ # assigned to stale threads.
cattr_accessor :allow_concurrency, :instance_writer => false
@@allow_concurrency = false
@@ -87,8 +87,25 @@ def delete(key, options = nil)
def delete_matched(matcher, options = nil)
log("delete matched", matcher.inspect, options)
+ end
+
+ def increment(key, amount = 1)
+ log("incrementing", key, amount)
+ if num = read(key)
+ write(key, num + amount)
+ else
+ nil
+ end
end
+ def decrement(key, amount = 1)
+ log("decrementing", key, amount)
+ if num = read(key)
+ write(key, num - amount)
+ else
+ nil
+ end
+ end
private
def log(operation, key, options)
@@ -29,12 +29,11 @@ def read(key, options = nil)
nil
end
- # Set key = value if key isn't already set. Pass :force => true
- # to unconditionally set key = value. Returns a boolean indicating
- # whether the key was set.
+ # Set key = value. Pass :unless_exist => true if you don't
+ # want to update the cache if the key is already set.
def write(key, value, options = nil)
super
- method = options && options[:force] ? :set : :add
+ method = options && options[:unless_exist] ? :add : :set
response = @data.send(method, key, value, expires_in(options), raw?(options))
response == Response::STORED
rescue MemCache::MemCacheError => e
@@ -49,15 +48,37 @@ def delete(key, options = nil)
rescue MemCache::MemCacheError => e
logger.error("MemCacheError (#{e}): #{e.message}")
false
+ end
+
+ def increment(key, amount = 1)
+ log("incrementing", key, amount)
+
+ response = @data.incr(key, amount)
+ response == Response::NOT_FOUND ? nil : response
+ rescue MemCache::MemCacheError
+ nil
end
+ def decrement(key, amount = 1)
+ log("decrement", key, amount)
+
+ response = data.decr(key, amount)
+ response == Response::NOT_FOUND ? nil : response
+ rescue MemCache::MemCacheError
+ nil
+ end
+
def delete_matched(matcher, options = nil)
super
raise "Not supported by Memcache"
- end
-
+ end
+
def clear
@data.flush_all
+ end
+
+ def stats
+ @data.stats
end
private
@@ -24,6 +24,10 @@ def delete_matched(matcher, options = nil)
super
@data.delete_if { |k,v| k =~ matcher }
end
+
+ def clear
+ @data.clear
+ end
end
end
end
@@ -135,12 +135,12 @@ def process
load_application_initializers
- # Prepare dispatcher callbacks and run 'prepare' callbacks
- prepare_dispatcher
-
# the framework is now fully initialized
after_initialize
+ # Prepare dispatcher callbacks and run 'prepare' callbacks
+ prepare_dispatcher
+
# Routing must be initialized after plugins to allow the former to extend the routes
initialize_routing

0 comments on commit 5514baf

Please sign in to comment.