diff options
author | Seb Bacon <seb.bacon@gmail.com> | 2011-08-29 14:55:33 +0100 |
---|---|---|
committer | Seb Bacon <seb.bacon@gmail.com> | 2011-08-29 14:56:00 +0100 |
commit | e57fa3d276d700ea21c97f8c2d3731f0f9d4c7ab (patch) | |
tree | 1c9e555bde2d3b1a2007841f02ae62b3c3520b37 /vendor/gems/rdoc-2.4.3/lib/rdoc/cache.rb | |
parent | 3084034493a428b2394a59b68921ed4b73a8cf7e (diff) | |
parent | b4aefe5a69bbd492959931f1c577a028ec361993 (diff) |
Attempt to merge current develop to theme
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 + |