Class: Rubyzen::Cache::ParseCache
- Inherits:
-
Object
- Object
- Rubyzen::Cache::ParseCache
- Defined in:
- lib/rubyzen/cache/parse_cache.rb
Overview
In-memory cache for parsed AST results, keyed by file path and SHA256 checksum. Automatically invalidates entries when file contents change.
Instance Method Summary collapse
-
#fetch_or_parse(file_path) { ... } ⇒ Object
Returns the cached result for the given file, or yields to parse and cache it.
-
#initialize ⇒ ParseCache
constructor
A new instance of ParseCache.
Constructor Details
#initialize ⇒ ParseCache
Returns a new instance of ParseCache.
8 9 10 |
# File 'lib/rubyzen/cache/parse_cache.rb', line 8 def initialize @cache = {} end |
Instance Method Details
#fetch_or_parse(file_path) { ... } ⇒ Object
Returns the cached result for the given file, or yields to parse and cache it.
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/rubyzen/cache/parse_cache.rb', line 17 def fetch_or_parse(file_path, &block) checksum = file_checksum(file_path) if @cache.key?(file_path) && @cache[file_path][:checksum] == checksum @cache[file_path][:result] else result = block.call @cache[file_path] = { checksum: checksum, result: result } result end end |