class Webgen::Cache
A cache object provides access to various caches to speed up rendering of a website:
- permanent
-
The permanent cache should be used for data that should be available between webgen runs.
- volatile
-
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 passes when writing nodes to the destination.
- standard
-
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
.
Attributes
The cache data stored in the current webgen run.
The cache data stored in the previous webgen run.
The permanent cache hash.
The volatile cache hash.
Public Class Methods
Create a new cache object.
# File lib/webgen/cache.rb 38 def initialize() 39 @old_data = {} 40 @new_data = {} 41 @volatile = {} 42 @permanent = {} 43 end
Public Instance Methods
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 47 def [](key) 48 if @old_data.has_key?(key) 49 @old_data[key] 50 else 51 @new_data[key] 52 end 53 end
Store value
identified by key
in the standard cache.
# File lib/webgen/cache.rb 56 def []=(key, value) 57 @new_data[key] = value 58 end
Return all caches that should be available between webgen runs.
# File lib/webgen/cache.rb 66 def dump 67 [@old_data.merge(@new_data), @permanent] 68 end
Reset the volatile cache.
# File lib/webgen/cache.rb 71 def reset_volatile_cache 72 @volatile = {} 73 end
Restore the cache from data
.
# File lib/webgen/cache.rb 61 def restore(data) 62 @old_data, @permanent = *data 63 end