Module: Ukiryu::ToolCache Private

Defined in:
lib/ukiryu/tool_cache.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Cache management for Tool instances

Provides centralized cache management for tool instances, with bounded LRU caching to prevent memory bloat.

Class Method Summary collapse

Class Method Details

.cacheCache

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.

Get the tools cache (bounded LRU cache)

Returns:

  • (Cache)

    the tools cache with max 50 entries and 1-hour TTL



15
16
17
# File 'lib/ukiryu/tool_cache.rb', line 15

def cache
  @cache ||= Ukiryu::Cache.new(max_size: 50, ttl: 3600)
end

.cache_key_for(name, options) ⇒ 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.

Generate a cache key for a tool

Cache keys are composed of: name-platform-shell-version to ensure different environments get different cached instances.

Parameters:

  • name (String, Symbol)

    the tool name

  • options (Hash)

    initialization options

Options Hash (options):

  • :platform (Symbol)

    the platform (defaults to Runtime platform)

  • :shell (Symbol)

    the shell (defaults to Runtime shell)

  • :version (String)

    the tool version (defaults to ‘latest’)

Returns:

  • (String)

    the cache key



47
48
49
50
51
52
53
# File 'lib/ukiryu/tool_cache.rb', line 47

def cache_key_for(name, options)
  runtime = Ukiryu::Runtime.instance
  platform = options[:platform] || runtime.platform
  shell = options[:shell] || runtime.shell
  version = options[:version] || 'latest'
  "#{name}-#{platform}-#{shell}-#{version}"
end

.clearvoid

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 method returns an undefined value.

Clear the tool cache

Also clears the Tools::Generator cache.



60
61
62
63
# File 'lib/ukiryu/tool_cache.rb', line 60

def clear
  cache.clear
  Ukiryu::Tools::Generator.clear_cache
end

.clear_definition_cachevoid

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 method returns an undefined value.

Clear the definition cache only

Clears the Definition::Loader cache without clearing tool instances.



70
71
72
# File 'lib/ukiryu/tool_cache.rb', line 70

def clear_definition_cache
  Ukiryu::Definition::Loader.clear_cache
end

.get(key) ⇒ Tool?

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.

Get a tool from the cache

Parameters:

  • key (String)

    the cache key

Returns:

  • (Tool, nil)

    the cached tool or nil if not found



23
24
25
# File 'lib/ukiryu/tool_cache.rb', line 23

def get(key)
  cache[key]
end

.set(key, tool) ⇒ void

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 method returns an undefined value.

Store a tool in the cache

Parameters:

  • key (String)

    the cache key

  • tool (Tool)

    the tool to cache



32
33
34
# File 'lib/ukiryu/tool_cache.rb', line 32

def set(key, tool)
  cache[key] = tool
end