A cache object provides access to various caches to speed up rendering of a website:
The permanent cache should be used for data that should be available between webgen runs.
The volatile cache is used for data that can easily be regenerated but might be expensive to do so. This cache is not stored between webgen runs.
The standard cache saves data between webgen runs and returns the cached data (not the newly set data) if it is available. This is useful, for example, to store file modifcation times and check if a file has been changed between runs.
The standard cache should be accessed through the [] method which returns the correct value and the []= method should be used for setting the new value. However, if you really need to access a particular value of the old or new standard cache, you can use the accessors old_data and new_data.
Return the cached data (or, if it is not available, the new data) identified by key from the standard cache.
# File lib/webgen/cache.rb, line 47 def [](key) if @old_data.has_key?(key) @old_data[key] else @new_data[key] end end
Store value identified by key in the standard cache.
# File lib/webgen/cache.rb, line 56 def []=(key, value) @new_data[key] = value end
Return all caches that should be available between webgen runs.
# File lib/webgen/cache.rb, line 67 def dump [@old_data.merge(@new_data), @permanent] end
Return the unique instance of the class name (a String). This method should be used when it is essential that webgen uses only one object of a class or when an object should automatically be recreated upon cache restoration (see restore).
# File lib/webgen/cache.rb, line 79 def instance(name) @permanent[:classes] << name unless @permanent[:classes].include?(name) (@volatile[:classes] ||= {})[name] ||= Common.const_for_name(name).new end
Reset the volatile cache.
# File lib/webgen/cache.rb, line 72 def reset_volatile_cache @volatile = {:classes => @volatile[:classes]} end
Restore the caches from data and recreate all cached instances (see instance).
# File lib/webgen/cache.rb, line 61 def restore(data) @old_data, @permanent = *data @permanent[:classes].each {|klass| instance(klass)} end
Generated with the Darkfish Rdoc Generator 2.