Class: Puppet::Environments::Cached Private

Inherits:
Combined show all
Defined in:
lib/puppet/environments.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Defined Under Namespace

Classes: Entry, NotCachedEntry, TTLEntry

Constant Summary collapse

INFINITY =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

1.0 / 0.0

Instance Method Summary collapse

Methods inherited from Combined

#list, #search_paths

Constructor Details

#initialize(*loaders) ⇒ Cached

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Cached.



277
278
279
280
# File 'lib/puppet/environments.rb', line 277

def initialize(*loaders)
  super
  @cache = {}
end

Instance Method Details

#clear(name) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Clears the cache of the environment with the given name. (The intention is that this could be used from a MANUAL cache eviction command (TBD)



294
295
296
# File 'lib/puppet/environments.rb', line 294

def clear(name)
  @cache.delete(name)
end

#clear_allObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Clears all cached environments. (The intention is that this could be used from a MANUAL cache eviction command (TBD)



300
301
302
# File 'lib/puppet/environments.rb', line 300

def clear_all()
  @cache = {}
end

#entry(env) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Creates a suitable cache entry given the time to live for one environment



315
316
317
318
319
320
321
322
323
324
325
# File 'lib/puppet/environments.rb', line 315

def entry(env)
  ttl = (conf = get_conf(env.name)) ? conf.environment_timeout : Puppet.settings.value(:environment_timeout)
  case ttl
  when 0
    NotCachedEntry.new(env)     # Entry that is always expired (avoids syscall to get time)
  when INFINITY
    Entry.new(env)              # Entry that never expires (avoids syscall to get time)
  else
    TTLEntry.new(env, ttl)
  end
end

#evict_if_expired(name) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Evicts the entry if it has expired



329
330
331
332
333
# File 'lib/puppet/environments.rb', line 329

def evict_if_expired(name)
  if (result = @cache[name]) && result.expired?
    @cache.delete(name)
  end
end

#get(name) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



282
283
284
285
286
287
288
289
290
# File 'lib/puppet/environments.rb', line 282

def get(name)
  evict_if_expired(name)
  if result = @cache[name]
    return result.value
  elsif (result = super(name))
    @cache[name] = entry(result)
    result
  end
end

#get_conf(name) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This implementation evicts the cache, and always gets the current configuration of the environment TODO: While this is wasteful since it needs to go on a search for the conf, it is too disruptive to optimize this.



308
309
310
311
# File 'lib/puppet/environments.rb', line 308

def get_conf(name)
  evict_if_expired(name)
  super name
end