aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/gems/rdoc-2.4.3/lib/rdoc/cache.rb
diff options
context:
space:
mode:
authorseb <seb@seb-U36JC>2011-11-24 09:21:36 +0000
committerseb <seb@seb-U36JC>2011-11-24 09:21:36 +0000
commita4e533f1588a5d34dca4ab462b58ddd83eed37c5 (patch)
tree58bb3b57ec5664e094ae151c18b6c1915256e364 /vendor/gems/rdoc-2.4.3/lib/rdoc/cache.rb
parentd473fce1d0451c913d3ef697d3b45bd58c6fff54 (diff)
parente649c2a7f19d0a75206149d886ff47b3ccda4e91 (diff)
Merge branch 'develop' into xapian-dcabo
Conflicts: spec/models/xapian_spec.rb
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
+