diff options
author | Robin Houston <robin@lenny.robin> | 2011-08-24 18:09:33 +0100 |
---|---|---|
committer | Robin Houston <robin@lenny.robin> | 2011-08-24 18:09:33 +0100 |
commit | 95ed2bc24312699cfce9bb6f9bc1418b15718bb1 (patch) | |
tree | 6639e8b140b0d74a8f93c2ab00d7a7faba41d6d7 /vendor/gems/rdoc-2.4.3/lib/rdoc/cache.rb | |
parent | 68a5989094f63a7e32fd6745b1c5739e038339f3 (diff) |
Add rdoc 2.4.3 to vendor/gems
Diffstat (limited to 'vendor/gems/rdoc-2.4.3/lib/rdoc/cache.rb')
-rw-r--r-- | vendor/gems/rdoc-2.4.3/lib/rdoc/cache.rb | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/vendor/gems/rdoc-2.4.3/lib/rdoc/cache.rb b/vendor/gems/rdoc-2.4.3/lib/rdoc/cache.rb new file mode 100644 index 000000000..bdd830a13 --- /dev/null +++ b/vendor/gems/rdoc-2.4.3/lib/rdoc/cache.rb @@ -0,0 +1,41 @@ +require 'thread' +require 'singleton' + +## +# A generic, thread-safe in-memory cache. It's used for caching +# RDoc::TemplatePage objects when generating RDoc output. + +class RDoc::Cache + + include Singleton + + ## + # Creates a new, empty cache + + def initialize + @contents = {} + @lock = Mutex.new + end + + ## + # Checks whether there's a value in the cache with key +key+. If so, then + # that value will be returned. Otherwise, the given block will be run, and + # its return value will be put into the cache, and returned. + + def cache(key) + @lock.synchronize do + @contents[key] ||= yield + end + end + + ## + # Clears the contents of the cache + + def clear + @lock.synchronize do + @contents.clear + end + end + +end + |