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.



269
270
271
272
# File 'lib/puppet/environments.rb', line 269

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)



286
287
288
# File 'lib/puppet/environments.rb', line 286

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)



292
293
294
# File 'lib/puppet/environments.rb', line 292

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



307
308
309
310
311
312
313
314
315
316
317
# File 'lib/puppet/environments.rb', line 307

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



321
322
323
324
325
# File 'lib/puppet/environments.rb', line 321

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.



274
275
276
277
278
279
280
281
282
# File 'lib/puppet/environments.rb', line 274

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.



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

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