Class Webgen::Cache
In: lib/webgen/cache.rb
Parent: Object
Error RenderError CommandNotFoundError LoadError NodeCreationError ::Rake::TaskLib WebgenTask Helpers Configuration Node Context\n[lib/webgen/context.rb\nlib/webgen/context/nodes.rb\nlib/webgen/context/render.rb\nlib/webgen/context/tags.rb] Tree FileSystem Sitemap Copy Feed Virtual Sitemap Directory Page Fragment Template Metainfo Memory Coderay Sitemap IncludeFile BreadcrumbTrail Langbar TikZ Menu Tags Fragments Resource Website Tidy Head Kramdown Less Xmllint Blocks Comparable Language Path StandardError CmdParse::CommandParser CommandParser CmdParse::Command RunCommand WebguiCommand CreateCommand ApplyCommand WebsiteAccess Main Loggable OutputPathHelpers ExecuteCommand Link Date Relocatable Metainfo ::Kramdown::Converter::Html KramdownHtmlConverter Cache Blackboard WebsiteManager Logger Page ProxyNode Utils Scss RDoc Sass Erb RDiscount Erubis Haml Maruku Builder RedCloth AccessHash TarArchive Stacked FileSystem lib/webgen/cache.rb lib/webgen/error.rb lib/webgen/languages.rb lib/webgen/context/render.rb lib/webgen/website.rb lib/webgen/blackboard.rb lib/webgen/tree.rb lib/webgen/websitemanager.rb lib/webgen/logger.rb lib/webgen/configuration.rb lib/webgen/path.rb lib/webgen/webgentask.rb lib/webgen/page.rb lib/webgen/node.rb ClassMethods WebsiteAccess lib/webgen/cli/run_command.rb lib/webgen/cli/utils.rb lib/webgen/cli/apply_command.rb lib/webgen/cli/webgui_command.rb lib/webgen/cli.rb lib/webgen/cli/create_command.rb Color CLI LanguageManager lib/webgen/output/filesystem.rb Output lib/webgen/common/sitemap.rb Common lib/webgen/sourcehandler/memory.rb lib/webgen/sourcehandler/metainfo.rb lib/webgen/sourcehandler/copy.rb lib/webgen/sourcehandler/directory.rb lib/webgen/sourcehandler.rb lib/webgen/sourcehandler/page.rb lib/webgen/sourcehandler/template.rb lib/webgen/sourcehandler/fragment.rb lib/webgen/sourcehandler/sitemap.rb lib/webgen/sourcehandler/virtual.rb lib/webgen/sourcehandler/feed.rb OutputPathHelpers Base SourceHandler lib/webgen/tag/coderay.rb lib/webgen/tag/relocatable.rb lib/webgen/tag/menu.rb lib/webgen/tag/langbar.rb lib/webgen/tag/executecommand.rb lib/webgen/tag/breadcrumbtrail.rb lib/webgen/tag/metainfo.rb lib/webgen/tag/includefile.rb lib/webgen/tag/link.rb lib/webgen/tag/date.rb lib/webgen/tag/tikz.rb lib/webgen/tag/sitemap.rb Base Tag lib/webgen/contentprocessor/less.rb lib/webgen/contentprocessor/scss.rb lib/webgen/contentprocessor/blocks.rb lib/webgen/contentprocessor/rdoc.rb lib/webgen/contentprocessor/sass.rb lib/webgen/contentprocessor/erb.rb lib/webgen/contentprocessor/rdiscount.rb lib/webgen/contentprocessor/tags.rb lib/webgen/contentprocessor/erubis.rb lib/webgen/contentprocessor/kramdown/html.rb lib/webgen/contentprocessor/haml.rb lib/webgen/contentprocessor/maruku.rb lib/webgen/contentprocessor/xmllint.rb lib/webgen/contentprocessor/kramdown.rb lib/webgen/contentprocessor/head.rb lib/webgen/contentprocessor/builder.rb lib/webgen/contentprocessor/tidy.rb lib/webgen/contentprocessor/redcloth.rb lib/webgen/contentprocessor/fragments.rb lib/webgen/contentprocessor.rb ContentProcessor lib/webgen/source/tararchive.rb lib/webgen/source/stacked.rb lib/webgen/source/resource.rb lib/webgen/source/filesystem.rb Source Loggable Webgen dot/m_82_0.png

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.

Methods

[]   []=   dump   instance   new   reset_volatile_cache   restore  

Attributes

new_data  [R]  The cache data stored in the current webgen run.
old_data  [R]  The cache data stored in the previous webgen run.
permanent  [R]  The permanent cache hash.
volatile  [R]  The volatile cache hash.

Public Class methods

Create a new cache object.

[Source]

    # 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

Return the cached data (or, if it is not available, the new data) identified by key from the standard cache.

[Source]

    # 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

Store value identified by key in the standard cache.

[Source]

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

Return all caches that should be available between webgen runs.

[Source]

    # File lib/webgen/cache.rb, line 68
68:     def dump
69:       [@old_data.merge(@new_data), @permanent]
70:     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).

[Source]

    # 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 the volatile cache.

[Source]

    # File lib/webgen/cache.rb, line 73
73:     def reset_volatile_cache
74:       @volatile = {:classes => @volatile[:classes]}
75:     end

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

[Source]

    # 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

[Validate]