class Middleman::Util::Cache
Simple shared cache implementation
Public Class Methods
new()
click to toggle source
Initialize
# File lib/middleman-core/util.rb, line 149 def initialize self.clear end
Public Instance Methods
clear()
click to toggle source
Clear the entire cache @return [void]
# File lib/middleman-core/util.rb, line 183 def clear @cache = {} end
fetch(*key) { || ... }
click to toggle source
Either get the cached key or save the contents of the block
@param key Anything Hash can use as a key
# File lib/middleman-core/util.rb, line 156 def fetch(*key) @cache[key] ||= yield end
get(key)
click to toggle source
Get a specific key
@param key Anything Hash can use as a key
# File lib/middleman-core/util.rb, line 171 def get(key) @cache[key] end
has_key?(key)
click to toggle source
Whether the key is in the cache
@param key Anything Hash can use as a key @return [Boolean]
# File lib/middleman-core/util.rb, line 164 def has_key?(key) @cache.has_key?(key) end
keys()
click to toggle source
Array of keys @return [Array]
# File lib/middleman-core/util.rb, line 177 def keys @cache.keys end
remove(*key)
click to toggle source
Remove a specific key @param key Anything Hash can use as a key
# File lib/middleman-core/util.rb, line 198 def remove(*key) @cache.delete(key) end
set(key, value)
click to toggle source
Set a specific key
@param key Anything Hash can use as a key @param value Cached value @return [void]
# File lib/middleman-core/util.rb, line 192 def set(key, value) @cache[key] = value end