Class: Puppet::Environments::Cached Private

Inherits:
Object
  • Object
show all
Includes:
Concurrent::Synchronized, 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, MRUEntry, NotCachedEntry

Class Method Summary collapse

Instance Method Summary collapse

Methods included from EnvironmentLoader

#get!

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.

 354 355 356 357 358
# File 'lib/puppet/environments.rb', line 354 def initialize(loader) @loader = loader @cache_expiration_service = Puppet::Environments::Cached.cache_expiration_service @cache = {} end

Class Method Details

.cache_expiration_serviceObject

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.

 350 351 352
# File 'lib/puppet/environments.rb', line 350 def self.cache_expiration_service @cache_expiration_service_singleton || 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.

 346 347 348
# File 'lib/puppet/environments.rb', line 346 def self.cache_expiration_service=(service) @cache_expiration_service_singleton = 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)

 439 440 441 442 443
# File 'lib/puppet/environments.rb', line 439 def clear(name) name = name.to_sym entry = @cache[name] clear_entry(name, entry) if entry 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)

 447 448 449 450 451 452 453 454 455 456
# File 'lib/puppet/environments.rb', line 447 def clear_all super @cache.each_pair do |name, entry| clear_entry(name, entry) end @cache = {} Puppet::GettextConfig.delete_environment_text_domains 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

 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528
# File 'lib/puppet/environments.rb', line 513 def entry(env) ttl = if (conf = get_conf(env.name)) conf.environment_timeout else Puppet[:environment_timeout] end 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 MRUEntry.new(env, ttl) # Entry that expires in ttl from when it was last touched  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

Parameters:

  • name (String, Symbol)

    The name of environment to find

Returns:

 393 394 395 396
# File 'lib/puppet/environments.rb', line 393 def get(name) entry = get_entry(name) entry ? entry.value : nil 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.

Parameters:

  • name (String, Symbol)

    The name of the environment whose configuration we are looking up

Returns:

  • (Puppet::Setting::EnvironmentConf, nil)

    the configuration for the requested environment, or nil if not found or no configuration is available

 491 492 493 494 495
# File 'lib/puppet/environments.rb', line 491 def get_conf(name) name = name.to_sym clear_if_expired(name, @cache[name]) @loader.get_conf(name) end

#guard(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.

Guard an environment so it can’t be evicted while it’s in use. The method may be called multiple times, provided it is unguarded the same number of times. If you call this method, you must call ‘unguard` in an ensure block.

 500 501 502 503
# File 'lib/puppet/environments.rb', line 500 def guard(name) entry = get_entry(name, false) entry.guard if entry end

#listArray<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.

Returns:

 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385
# File 'lib/puppet/environments.rb', line 361 def list # Evict all that have expired, in the same way as `get`  clear_all_expired # Evict all that was removed from disk  cached_envs = @cache.keys.map!(&:to_sym) loader_envs = @loader.list.map!(&:name) removed_envs = cached_envs - loader_envs removed_envs.each do |env_name| Puppet.debug { "Environment no longer exists '#{env_name}'" } clear(env_name) end @loader.list.map do |env| name = env.name old_entry = @cache[name] if old_entry old_entry.value else add_entry(name, entry(env)) env end end end

#search_pathsArray<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.

Returns:

  • (Array<String>)

    The URIs of the load locations

 388 389 390
# File 'lib/puppet/environments.rb', line 388 def search_paths @loader.search_paths end

#unguard(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.

Unguard an environment.

 506 507 508 509
# File 'lib/puppet/environments.rb', line 506 def unguard(name) entry = get_entry(name, false) entry.unguard if entry end