Class: Puppet::Environments::Cached Private
- Includes:
- EnvironmentLoader
- 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: DefaultCacheExpirationService, Entry, NotCachedEntry, TTLEntry
Class Method Summary collapse
Instance Method Summary collapse
-
#clear(name) ⇒ Object
private
Clears the cache of the environment with the given name.
-
#clear_all ⇒ Object
private
Clears all cached environments.
-
#entry(env) ⇒ Object
private
Creates a suitable cache entry given the time to live for one environment.
-
#evict_if_expired(name) ⇒ Object
private
Evicts the entry if it has expired Also clears caches in Settings that may prevent the entry from being updated.
-
#get(name) ⇒ Puppet::Node::Environment?
private
Find a named environment.
-
#get_conf(name) ⇒ Puppet::Setting::EnvironmentConf?
private
This implementation evicts the cache, and always gets the current configuration of the environment.
-
#initialize(loader) ⇒ Cached
constructor
private
A new instance of Cached.
-
#list ⇒ Array<Puppet::Node::Environment>
private
All of the environments known to the loader.
-
#search_paths ⇒ Array<String>
private
A list of indicators of where the loader is getting its environments from.
Methods included from EnvironmentLoader
Constructor Details
#initialize(loader) ⇒ 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.
285 286 287 288 289 |
# File 'lib/puppet/environments.rb', line 285 def initialize(loader) @loader = loader @cache = {} @cache_expiration_service = Puppet::Environments::Cached.cache_expiration_service end |
Class Method Details
.cache_expiration_service ⇒ 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.
281 282 283 |
# File 'lib/puppet/environments.rb', line 281 def self.cache_expiration_service @cache_expiration_service || DefaultCacheExpirationService.new end |
.cache_expiration_service=(service) ⇒ 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.
277 278 279 |
# File 'lib/puppet/environments.rb', line 277 def self.cache_expiration_service=(service) @cache_expiration_service = service 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)
314 315 316 |
# File 'lib/puppet/environments.rb', line 314 def clear(name) @cache.delete(name) end |
#clear_all ⇒ 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 all cached environments. (The intention is that this could be used from a MANUAL cache eviction command (TBD)
320 321 322 |
# File 'lib/puppet/environments.rb', line 320 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
339 340 341 342 343 344 345 346 347 348 349 350 351 |
# File 'lib/puppet/environments.rb', line 339 def entry(env) @cache_expiration_service.created(env) ttl = (conf = get_conf(env.name)) ? conf.environment_timeout : Puppet.settings.value(:environment_timeout) Puppet.debug {"Caching environment '#{env.name}' (cache ttl: #{ttl})"} case ttl when 0 NotCachedEntry.new(env) # Entry that is always expired (avoids syscall to get time) when Float::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 Also clears caches in Settings that may prevent the entry from being updated
355 356 357 358 359 360 361 362 363 |
# File 'lib/puppet/environments.rb', line 355 def evict_if_expired(name) if (result = @cache[name]) && (result.expired? || @cache_expiration_service.expired?(name)) Puppet.debug {"Evicting cache entry for environment '#{name}'"} @cache.delete(name) @cache_expiration_service.evicted(name) Puppet.settings.clear_environment_settings(name) end end |
#get(name) ⇒ Puppet::Node::Environment?
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.
Find a named environment
302 303 304 305 306 307 308 309 310 |
# File 'lib/puppet/environments.rb', line 302 def get(name) evict_if_expired(name) if result = @cache[name] return result.value elsif (result = @loader.get(name)) @cache[name] = entry(result) result end end |
#get_conf(name) ⇒ Puppet::Setting::EnvironmentConf?
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.
Attempt to obtain the initial configuration for the environment. Not all loaders can provide this.
332 333 334 335 |
# File 'lib/puppet/environments.rb', line 332 def get_conf(name) evict_if_expired(name) @loader.get_conf(name) end |
#list ⇒ Array<Puppet::Node::Environment>
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 All of the environments known to the loader.
292 293 294 |
# File 'lib/puppet/environments.rb', line 292 def list @loader.list end |
#search_paths ⇒ Array<String>
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.
A list of indicators of where the loader is getting its environments from.
297 298 299 |
# File 'lib/puppet/environments.rb', line 297 def search_paths @loader.search_paths end |