Parent

Class Index [+]

Quicksearch

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 webgen runs.

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

permanent[R]

The permanent cache hash.

volatile[R]

The volatile cache hash.

old_data[R]

The cache data stored in the previous webgen run.

new_data[R]

The cache data stored in the current webgen run.

Public Class Methods

new() click to toggle source

Create a new cache object.

    # File lib/webgen/cache.rb, line 39
39:     def initialize()
40:       @old_data = {}
41:       @new_data = {}
42:       @volatile = {}
43:       @permanent = {:classes => []}
44:     end

Public Instance Methods

[](key) click to toggle source

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 48
48:     def [](key)
49:       if @old_data.has_key?(key)
50:         @old_data[key]
51:       else
52:         @new_data[key]
53:       end
54:     end
[]=(key, value) click to toggle source

Store value identified by key in the standard cache.

    # File lib/webgen/cache.rb, line 57
57:     def []=(key, value)
58:       @new_data[key] = value
59:     end
dump() click to toggle source

Return all caches that should be available between webgen runs.

    # File lib/webgen/cache.rb, line 68
68:     def dump
69:       [@old_data.merge(@new_data), @permanent]
70:     end
instance(name) click to toggle source

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 #).

    # File lib/webgen/cache.rb, line 80
80:     def instance(name)
81:       @permanent[:classes] << name unless @permanent[:classes].include?(name)
82:       (@volatile[:classes] ||= {})[name] ||= Common.const_for_name(name).new
83:     end
reset_volatile_cache() click to toggle source

Reset the volatile cache.

    # File lib/webgen/cache.rb, line 73
73:     def reset_volatile_cache
74:       @volatile = {:classes => @volatile[:classes]}
75:     end
restore(data) click to toggle source

Restore the caches from data and recreate all cached instances (see #).

    # File lib/webgen/cache.rb, line 62
62:     def restore(data)
63:       @old_data, @permanent = *data
64:       @permanent[:classes].each {|klass| instance(klass)}
65:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.