aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/key_generator.rb
diff options
context:
space:
mode:
authorthedarkone <thedarkone2@gmail.com>2012-12-13 14:47:33 +0100
committerthedarkone <thedarkone2@gmail.com>2012-12-14 12:18:47 +0100
commit45448a578877f6a753492113d72cc3512a6f1720 (patch)
tree9c44e7fd9395bff738deeb4ab76db68c0efa3734 /activesupport/lib/active_support/key_generator.rb
parentd668544785550712677ae999dfb0644e640ec729 (diff)
downloadrails-45448a578877f6a753492113d72cc3512a6f1720.tar.gz
rails-45448a578877f6a753492113d72cc3512a6f1720.tar.bz2
rails-45448a578877f6a753492113d72cc3512a6f1720.zip
Replace some global Hash usages with the new thread safe cache.
Summary of the changes: * Add thread_safe gem. * Use thread safe cache for digestor caching. * Replace manual synchronization with ThreadSafe::Cache in Relation::Delegation. * Replace @attribute_method_matchers_cache Hash with ThreadSafe::Cache. * Use TS::Cache to avoid the synchronisation overhead on listener retrieval. * Replace synchronisation with TS::Cache usage. * Use a preallocated array for performance/memory reasons. * Update the controllers cache to the new AS::Dependencies::ClassCache API. The original @controllers cache no longer makes much sense after @tenderlove's changes in 7b6bfe84f3 and f345e2380c. * Use TS::Cache in the connection pool to avoid locking overhead. * Use TS::Cache in ConnectionHandler.
Diffstat (limited to 'activesupport/lib/active_support/key_generator.rb')
-rw-r--r--activesupport/lib/active_support/key_generator.rb8
1 files changed, 3 insertions, 5 deletions
diff --git a/activesupport/lib/active_support/key_generator.rb b/activesupport/lib/active_support/key_generator.rb
index 6beb2b6afa..71654dbb87 100644
--- a/activesupport/lib/active_support/key_generator.rb
+++ b/activesupport/lib/active_support/key_generator.rb
@@ -1,4 +1,4 @@
-require 'mutex_m'
+require 'thread_safe'
require 'openssl'
module ActiveSupport
@@ -28,16 +28,14 @@ module ActiveSupport
class CachingKeyGenerator
def initialize(key_generator)
@key_generator = key_generator
- @cache_keys = {}.extend(Mutex_m)
+ @cache_keys = ThreadSafe::Cache.new
end
# Returns a derived key suitable for use. The default key_size is chosen
# to be compatible with the default settings of ActiveSupport::MessageVerifier.
# i.e. OpenSSL::Digest::SHA1#block_length
def generate_key(salt, key_size=64)
- @cache_keys.synchronize do
- @cache_keys["#{salt}#{key_size}"] ||= @key_generator.generate_key(salt, key_size)
- end
+ @cache_keys["#{salt}#{key_size}"] ||= @key_generator.generate_key(salt, key_size)
end
end