Class: Middleman::Util::Cache
- Inherits:
-
Object
- Object
- Middleman::Util::Cache
- Defined in:
- lib/middleman-core/util.rb
Overview
Simple shared cache implementation
Instance Method Summary collapse
-
#clear ⇒ void
Clear the entire cache.
-
#fetch(*key) ⇒ Object
Either get the cached key or save the contents of the block.
-
#get(key) ⇒ Object
Get a specific key.
-
#has_key?(key) ⇒ Boolean
Whether the key is in the cache.
-
#initialize ⇒ Cache
constructor
Initialize.
-
#keys ⇒ Array
Array of keys.
-
#remove(*key) ⇒ Object
Remove a specific key.
-
#set(key, value) ⇒ void
Set a specific key.
Constructor Details
#initialize ⇒ Cache
Initialize
125 126 127 |
# File 'lib/middleman-core/util.rb', line 125 def initialize self.clear end |
Instance Method Details
#clear ⇒ void
This method returns an undefined value.
Clear the entire cache
159 160 161 |
# File 'lib/middleman-core/util.rb', line 159 def clear @cache = {} end |
#fetch(*key) ⇒ Object
Either get the cached key or save the contents of the block
132 133 134 |
# File 'lib/middleman-core/util.rb', line 132 def fetch(*key) @cache[key] ||= yield end |
#get(key) ⇒ Object
Get a specific key
147 148 149 |
# File 'lib/middleman-core/util.rb', line 147 def get(key) @cache[key] end |
#has_key?(key) ⇒ Boolean
Whether the key is in the cache
140 141 142 |
# File 'lib/middleman-core/util.rb', line 140 def has_key?(key) @cache.has_key?(key) end |
#keys ⇒ Array
Array of keys
153 154 155 |
# File 'lib/middleman-core/util.rb', line 153 def keys @cache.keys end |
#remove(*key) ⇒ Object
Remove a specific key
174 175 176 |
# File 'lib/middleman-core/util.rb', line 174 def remove(*key) @cache.delete(key) end |
#set(key, value) ⇒ void
This method returns an undefined value.
Set a specific key
168 169 170 |
# File 'lib/middleman-core/util.rb', line 168 def set(key, value) @cache[key] = value end |