Skip to content

Commit

Permalink
Merge branch 'master' of git@github.com:rails/rails
Browse files Browse the repository at this point in the history
  • Loading branch information
David Heinemeier Hansson committed Apr 29, 2008
2 parents 0780563 + 5be5305 commit 5514baf
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 16 deletions.
7 changes: 4 additions & 3 deletions actionpack/lib/action_controller/base.rb
Expand Up @@ -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

Expand Down
5 changes: 2 additions & 3 deletions actionpack/test/controller/session/mem_cache_store_test.rb
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion activerecord/lib/active_record/base.rb
Expand Up @@ -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

Expand Down
17 changes: 17 additions & 0 deletions activesupport/lib/active_support/cache.rb
Expand Up @@ -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)
Expand Down
33 changes: 27 additions & 6 deletions activesupport/lib/active_support/cache/mem_cache_store.rb
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions activesupport/lib/active_support/cache/memory_store.rb
Expand Up @@ -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
6 changes: 3 additions & 3 deletions railties/lib/initializer.rb
Expand Up @@ -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

Expand Down

0 comments on commit 5514baf

Please sign in to comment.