aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/gems/rdoc-2.4.3/lib/rdoc/cache.rb
diff options
context:
space:
mode:
authorDavid Cabo <david@calibea.com>2011-10-13 00:29:51 +0200
committerDavid Cabo <david@calibea.com>2011-10-13 00:29:51 +0200
commitc8983b923e4dc7db9ba22156daaddd94d2b5ed4d (patch)
tree7741c3655fe5e3cbc90dd20a4626ac7acc1bf6b0 /vendor/gems/rdoc-2.4.3/lib/rdoc/cache.rb
parenta29b3aaf0ae77af49d38813b62dddcb6889c1ebe (diff)
parente13127a8ebc8bf8379d92f778af5a2bb6931d80c (diff)
Merge branch 'release/0.4'0.4
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.rb41
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
+