aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/cache.rb
diff options
context:
space:
mode:
authorJoshua Peek <josh@joshpeek.com>2008-07-17 15:29:30 -0500
committerJoshua Peek <josh@joshpeek.com>2008-07-17 15:29:30 -0500
commit94cf6675d516a0196f0222694f26dcd4c29c49c6 (patch)
tree92aafbaef7d25310f157edb11d5e764b44eb1e45 /activesupport/lib/active_support/cache.rb
parent99930d499e424f4560b371412e05d10476216ece (diff)
downloadrails-94cf6675d516a0196f0222694f26dcd4c29c49c6.tar.gz
rails-94cf6675d516a0196f0222694f26dcd4c29c49c6.tar.bz2
rails-94cf6675d516a0196f0222694f26dcd4c29c49c6.zip
Cleanup ActiveSupport::Cache::ThreadSafety module and add test coverage
Diffstat (limited to 'activesupport/lib/active_support/cache.rb')
-rw-r--r--activesupport/lib/active_support/cache.rb32
1 files changed, 11 insertions, 21 deletions
diff --git a/activesupport/lib/active_support/cache.rb b/activesupport/lib/active_support/cache.rb
index 3e3dc18263..57c6a6331d 100644
--- a/activesupport/lib/active_support/cache.rb
+++ b/activesupport/lib/active_support/cache.rb
@@ -21,7 +21,7 @@ module ActiveSupport
expanded_cache_key = namespace ? "#{namespace}/" : ""
if ENV["RAILS_CACHE_ID"] || ENV["RAILS_APP_VERSION"]
- expanded_cache_key << "#{ENV["RAILS_CACHE_ID"] || ENV["RAILS_APP_VERSION"]}/"
+ expanded_cache_key << "#{ENV["RAILS_CACHE_ID"] || ENV["RAILS_APP_VERSION"]}/"
end
expanded_cache_key << case
@@ -40,13 +40,8 @@ module ActiveSupport
class Store
cattr_accessor :logger
- def initialize
- end
-
def threadsafe!
- @mutex = Mutex.new
- self.class.send :include, ThreadSafety
- self
+ extend ThreadSafety
end
# Pass <tt>:force => true</tt> to force a cache miss.
@@ -110,29 +105,24 @@ module ActiveSupport
nil
end
end
-
+
private
def log(operation, key, options)
logger.debug("Cache #{operation}: #{key}#{options ? " (#{options.inspect})" : ""}") if logger && !@logger_off
end
end
-
module ThreadSafety #:nodoc:
- def read(key, options = nil) #:nodoc:
- @mutex.synchronize { super }
- end
-
- def write(key, value, options = nil) #:nodoc:
- @mutex.synchronize { super }
- end
-
- def delete(key, options = nil) #:nodoc:
- @mutex.synchronize { super }
+ def self.extended(object) #:nodoc:
+ object.instance_variable_set(:@mutex, Mutex.new)
end
- def delete_matched(matcher, options = nil) #:nodoc:
- @mutex.synchronize { super }
+ %w(read write delete delete_matched exist? increment decrement).each do |method|
+ module_eval <<-EOS, __FILE__, __LINE__
+ def #{method}(*args)
+ @mutex.synchronize { super }
+ end
+ EOS
end
end
end