Class: Puppet::Environments::Cached Private
- 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
-
#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.
-
#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.
-
#guard(name) ⇒ Object
private
Guard an environment so it can't be evicted while it's in use.
-
#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.
-
#unguard(name) ⇒ Object
private
Unguard an environment.
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.
347 348 349 350 351 |
# File 'lib/puppet/environments.rb', line 347 def initialize(loader) @loader = loader @cache_expiration_service = Puppet::Environments::Cached.cache_expiration_service @cache = {} 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.
343 344 345 |
# File 'lib/puppet/environments.rb', line 343 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.
339 340 341 |
# File 'lib/puppet/environments.rb', line 339 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)
432 433 434 435 436 |
# File 'lib/puppet/environments.rb', line 432 def clear(name) name = name.to_sym entry = @cache[name] clear_entry(name, entry) if entry 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)
440 441 442 443 444 445 446 447 448 449 |
# File 'lib/puppet/environments.rb', line 440 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
506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 |
# File 'lib/puppet/environments.rb', line 506 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
386 387 388 389 |
# File 'lib/puppet/environments.rb', line 386 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.
484 485 486 487 488 |
# File 'lib/puppet/environments.rb', line 484 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.
493 494 495 496 |
# File 'lib/puppet/environments.rb', line 493 def guard(name) entry = get_entry(name, false) entry.guard if entry 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.
354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 |
# File 'lib/puppet/environments.rb', line 354 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_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.
381 382 383 |
# File 'lib/puppet/environments.rb', line 381 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.
499 500 501 502 |
# File 'lib/puppet/environments.rb', line 499 def unguard(name) entry = get_entry(name, false) entry.unguard if entry end |