Class: Webgen::Cache
- Inherits:
-
Object
- Object
- Webgen::Cache
- Defined in:
- lib/webgen/cache.rb
Overview
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
.
Instance Attribute Summary collapse
-
#new_data ⇒ Object
readonly
The cache data stored in the current webgen run.
-
#old_data ⇒ Object
readonly
The cache data stored in the previous webgen run.
-
#permanent ⇒ Object
readonly
The permanent cache hash.
-
#volatile ⇒ Object
readonly
The volatile cache hash.
Instance Method Summary collapse
-
#[](key) ⇒ Object
Return the cached data (or, if it is not available, the new data) identified by
key
from the standard cache. -
#[]=(key, value) ⇒ Object
Store
value
identified bykey
in the standard cache. -
#dump ⇒ Object
Return all caches that should be available between webgen runs.
-
#initialize ⇒ Cache
constructor
Create a new cache object.
-
#reset_volatile_cache ⇒ Object
Reset the volatile cache.
-
#restore(data) ⇒ Object
Restore the cache from
data
.
Constructor Details
#initialize ⇒ Cache
Create a new cache object.
39 40 41 42 43 44 |
# File 'lib/webgen/cache.rb', line 39 def initialize() @old_data = {} @new_data = {} @volatile = {} @permanent = {} end |
Instance Attribute Details
#new_data ⇒ Object (readonly)
The cache data stored in the current webgen run.
36 37 38 |
# File 'lib/webgen/cache.rb', line 36 def new_data @new_data end |
#old_data ⇒ Object (readonly)
The cache data stored in the previous webgen run.
33 34 35 |
# File 'lib/webgen/cache.rb', line 33 def old_data @old_data end |
#permanent ⇒ Object (readonly)
The permanent cache hash.
27 28 29 |
# File 'lib/webgen/cache.rb', line 27 def permanent @permanent end |
#volatile ⇒ Object (readonly)
The volatile cache hash.
30 31 32 |
# File 'lib/webgen/cache.rb', line 30 def volatile @volatile end |
Instance Method Details
#[](key) ⇒ Object
Return the cached data (or, if it is not available, the new data) identified by key
from the standard cache.
48 49 50 51 52 53 54 |
# File 'lib/webgen/cache.rb', line 48 def [](key) if @old_data.has_key?(key) @old_data[key] else @new_data[key] end end |
#[]=(key, value) ⇒ Object
Store value
identified by key
in the standard cache.
57 58 59 |
# File 'lib/webgen/cache.rb', line 57 def []=(key, value) @new_data[key] = value end |
#dump ⇒ Object
Return all caches that should be available between webgen runs.
67 68 69 |
# File 'lib/webgen/cache.rb', line 67 def dump [@old_data.merge(@new_data), @permanent] end |
#reset_volatile_cache ⇒ Object
Reset the volatile cache.
72 73 74 |
# File 'lib/webgen/cache.rb', line 72 def reset_volatile_cache @volatile = {} end |
#restore(data) ⇒ Object
Restore the cache from data
.
62 63 64 |
# File 'lib/webgen/cache.rb', line 62 def restore(data) @old_data, @permanent = *data end |