Class: Ukiryu::Shell::InstanceCache

Inherits:
Object
  • Object
show all
Defined in:
lib/ukiryu/shell/instance_cache.rb

Overview

Cached shell instances for performance

Reuses shell instances to avoid repeated object creation in hot paths. Thread-safe using Mutex.

Class Method Summary collapse

Class Method Details

.clearObject

Clear the cache (mainly for testing)



28
29
30
31
32
# File 'lib/ukiryu/shell/instance_cache.rb', line 28

def clear
  @mutex.synchronize do
    @cache.clear
  end
end

.instance_for(name) ⇒ Shell::Base

Get a cached shell instance for the given shell name

Parameters:

  • name (Symbol)

    the shell name or platform group

Returns:



20
21
22
23
24
# File 'lib/ukiryu/shell/instance_cache.rb', line 20

def instance_for(name)
  @mutex.synchronize do
    @cache[name] ||= create_instance(name)
  end
end

.sizeInteger

Get cache size (for debugging)

Returns:

  • (Integer)

    number of cached instances



38
39
40
41
42
# File 'lib/ukiryu/shell/instance_cache.rb', line 38

def size
  @mutex.synchronize do
    @cache.size
  end
end