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



120
121
122
# File 'lib/middleman-core/util.rb', line 120

def initialize
  self.clear
end

Instance Method Details

#clearvoid

This method returns an undefined value.

Clear the entire cache



154
155
156
# File 'lib/middleman-core/util.rb', line 154

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



127
128
129
# File 'lib/middleman-core/util.rb', line 127

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

#get(key) ⇒ Object

Get a specific key

Parameters:

  • key

    Anything Hash can use as a key



142
143
144
# File 'lib/middleman-core/util.rb', line 142

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)


135
136
137
# File 'lib/middleman-core/util.rb', line 135

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

#keysArray

Array of keys

Returns:

  • (Array)


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

def keys
  @cache.keys
end

#remove(*key) ⇒ Object

Remove a specific key

Parameters:

  • key

    Anything Hash can use as a key



169
170
171
# File 'lib/middleman-core/util.rb', line 169

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



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

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