aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@envy8-2.local>2008-04-29 16:43:47 -0500
committerDavid Heinemeier Hansson <david@envy8-2.local>2008-04-29 16:43:47 -0500
commit5514baf63d6d5e19a84c59a0c2cf74f442daed9c (patch)
treeecde263c340d9fdbcf0f3ba9d9276e38f7fbfb96
parent0780563ae7b2df74613550f1438d13459cb10b1f (diff)
parent5be53058775a1482c1e5655dcb0ca4430cf0dbe1 (diff)
downloadrails-5514baf63d6d5e19a84c59a0c2cf74f442daed9c.tar.gz
rails-5514baf63d6d5e19a84c59a0c2cf74f442daed9c.tar.bz2
rails-5514baf63d6d5e19a84c59a0c2cf74f442daed9c.zip
Merge branch 'master' of git@github.com:rails/rails
-rwxr-xr-xactionpack/lib/action_controller/base.rb7
-rw-r--r--actionpack/test/controller/session/mem_cache_store_test.rb5
-rwxr-xr-xactiverecord/lib/active_record/base.rb4
-rw-r--r--activesupport/lib/active_support/cache.rb17
-rw-r--r--activesupport/lib/active_support/cache/mem_cache_store.rb33
-rw-r--r--activesupport/lib/active_support/cache/memory_store.rb4
-rw-r--r--railties/lib/initializer.rb6
7 files changed, 60 insertions, 16 deletions
diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb
index 0c0d0ec4ac..3322a41299 100755
--- a/actionpack/lib/action_controller/base.rb
+++ b/actionpack/lib/action_controller/base.rb
@@ -277,9 +277,10 @@ module ActionController #:nodoc:
@@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
diff --git a/actionpack/test/controller/session/mem_cache_store_test.rb b/actionpack/test/controller/session/mem_cache_store_test.rb
index df48e6d9c5..a7d48431f8 100644
--- a/actionpack/test/controller/session/mem_cache_store_test.rb
+++ b/actionpack/test/controller/session/mem_cache_store_test.rb
@@ -62,9 +62,8 @@ class MemCacheStoreTest < Test::Unit::TestCase
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
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index 300688453a..63306644fb 100755
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -423,7 +423,9 @@ module ActiveRecord #: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
diff --git a/activesupport/lib/active_support/cache.rb b/activesupport/lib/active_support/cache.rb
index 64394afec4..463cba6cf0 100644
--- a/activesupport/lib/active_support/cache.rb
+++ b/activesupport/lib/active_support/cache.rb
@@ -87,8 +87,25 @@ module ActiveSupport
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)
diff --git a/activesupport/lib/active_support/cache/mem_cache_store.rb b/activesupport/lib/active_support/cache/mem_cache_store.rb
index 9b787702b2..bfe7e2ccf3 100644
--- a/activesupport/lib/active_support/cache/mem_cache_store.rb
+++ b/activesupport/lib/active_support/cache/mem_cache_store.rb
@@ -29,12 +29,11 @@ module ActiveSupport
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 @@ module ActiveSupport
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
diff --git a/activesupport/lib/active_support/cache/memory_store.rb b/activesupport/lib/active_support/cache/memory_store.rb
index e0aba6b19a..4872e025cd 100644
--- a/activesupport/lib/active_support/cache/memory_store.rb
+++ b/activesupport/lib/active_support/cache/memory_store.rb
@@ -24,6 +24,10 @@ module ActiveSupport
super
@data.delete_if { |k,v| k =~ matcher }
end
+
+ def clear
+ @data.clear
+ end
end
end
end \ No newline at end of file
diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb
index e36f917b15..ea61d4e4fe 100644
--- a/railties/lib/initializer.rb
+++ b/railties/lib/initializer.rb
@@ -135,12 +135,12 @@ module Rails
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