Class: Middleman::Util::Cache

Inherits:
Object
  • Object
show all
Defined in:
lib/middleman-core/util.rb

Overview

Simple shared cache implementation

Instance Method Summary collapse

Constructor Details

#initializeCache

Initialize



149
150
151
# File 'lib/middleman-core/util.rb', line 149

def initialize
  self.clear
end

Instance Method Details

#clearvoid

This method returns an undefined value.

Clear the entire cache



183
184
185
# File 'lib/middleman-core/util.rb', line 183

def clear
  @cache = {}
end

#fetch(*key) ⇒ Object

Either get the cached key or save the contents of the block

Parameters:

  • key

    Anything Hash can use as a key



156
157
158
# File 'lib/middleman-core/util.rb', line 156

def fetch(*key)
  @cache[key] ||= yield
end

#get(key) ⇒ Object

Get a specific key

Parameters:

  • key

    Anything Hash can use as a key



171
172
173
# File 'lib/middleman-core/util.rb', line 171

def get(key)
  @cache[key]
end

#has_key?(key) ⇒ Boolean

Whether the key is in the cache

Parameters:

  • key

    Anything Hash can use as a key

Returns:

  • (Boolean)


164
165
166
# File 'lib/middleman-core/util.rb', line 164

def has_key?(key)
  @cache.has_key?(key)
end

#keysArray

Array of keys

Returns:

  • (Array)


177
178
179
# File 'lib/middleman-core/util.rb', line 177

def keys
  @cache.keys
end

#remove(*key) ⇒ Object

Remove a specific key

Parameters:

  • key

    Anything Hash can use as a key



198
199
200
# File 'lib/middleman-core/util.rb', line 198

def remove(*key)
  @cache.delete(key)
end

#set(key, value) ⇒ void

This method returns an undefined value.

Set a specific key

Parameters:

  • key

    Anything Hash can use as a key

  • value

    Cached value



192
193
194
# File 'lib/middleman-core/util.rb', line 192

def set(key, value)
  @cache[key] = value
end