Class: Yard::Lint::CommandCache
- Inherits:
-
Object
- Object
- Yard::Lint::CommandCache
- Defined in:
- lib/yard/lint/command_cache.rb
Overview
Cache for YARD command executions to avoid running identical commands multiple times This provides a transparent optimization layer - validators don’t need to know about it
Instance Method Summary collapse
-
#execute(command_string) ⇒ Hash
Execute a command through the cache If the command has been executed before, return cached result Otherwise execute and cache the result.
-
#initialize ⇒ CommandCache
constructor
A new instance of CommandCache.
-
#stats ⇒ Hash
Get cache statistics.
Constructor Details
#initialize ⇒ CommandCache
Returns a new instance of CommandCache.
8 9 10 11 12 |
# File 'lib/yard/lint/command_cache.rb', line 8 def initialize @cache = {} @hits = 0 @misses = 0 end |
Instance Method Details
#execute(command_string) ⇒ Hash
Note:
Returns a deep clone to prevent validators from modifying cached data
Execute a command through the cache If the command has been executed before, return cached result Otherwise execute and cache the result
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/yard/lint/command_cache.rb', line 20 def execute(command_string) cache_key = generate_cache_key(command_string) if @cache.key?(cache_key) @hits += 1 deep_clone(@cache[cache_key]) else @misses += 1 result = execute_command(command_string) @cache[cache_key] = deep_clone(result) result end end |
#stats ⇒ Hash
Get cache statistics
36 37 38 39 40 41 42 43 |
# File 'lib/yard/lint/command_cache.rb', line 36 def stats { hits: @hits, misses: @misses, total: @hits + @misses, saved_executions: @hits } end |