Class: GitJump::Utils::ConfigCache
- Inherits:
-
Object
- Object
- GitJump::Utils::ConfigCache
- Defined in:
- lib/git_jump/utils/config_cache.rb
Overview
Caches parsed TOML configuration for faster startup Inspired by dotsync’s ConfigCache implementation
Instance Attribute Summary collapse
-
#cache_dir ⇒ Object
readonly
Returns the value of attribute cache_dir.
-
#cache_file ⇒ Object
readonly
Returns the value of attribute cache_file.
-
#config_path ⇒ Object
readonly
Returns the value of attribute config_path.
-
#meta_file ⇒ Object
readonly
Returns the value of attribute meta_file.
Instance Method Summary collapse
-
#initialize(config_path) ⇒ ConfigCache
constructor
A new instance of ConfigCache.
- #load ⇒ Object
Constructor Details
#initialize(config_path) ⇒ ConfigCache
Returns a new instance of ConfigCache.
14 15 16 17 18 19 20 21 22 |
# File 'lib/git_jump/utils/config_cache.rb', line 14 def initialize(config_path) @config_path = File.(config_path) @cache_dir = File.join(Utils::XDG.data_home, "git-jump", "config_cache") # Use hash of real path for cache filename to support multiple configs cache_key = Digest::SHA256.hexdigest(File.exist?(@config_path) ? File.realpath(@config_path) : @config_path) @cache_file = File.join(@cache_dir, "#{cache_key}.cache") @meta_file = File.join(@cache_dir, "#{cache_key}.meta") end |
Instance Attribute Details
#cache_dir ⇒ Object (readonly)
Returns the value of attribute cache_dir.
12 13 14 |
# File 'lib/git_jump/utils/config_cache.rb', line 12 def cache_dir @cache_dir end |
#cache_file ⇒ Object (readonly)
Returns the value of attribute cache_file.
12 13 14 |
# File 'lib/git_jump/utils/config_cache.rb', line 12 def cache_file @cache_file end |
#config_path ⇒ Object (readonly)
Returns the value of attribute config_path.
12 13 14 |
# File 'lib/git_jump/utils/config_cache.rb', line 12 def config_path @config_path end |
#meta_file ⇒ Object (readonly)
Returns the value of attribute meta_file.
12 13 14 |
# File 'lib/git_jump/utils/config_cache.rb', line 12 def @meta_file end |
Instance Method Details
#load ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/git_jump/utils/config_cache.rb', line 24 def load # Skip cache if disabled via environment variable return parse_toml if ENV["GIT_JUMP_NO_CACHE"] return parse_and_cache unless valid_cache? # Fast path: load from cache Marshal.load(File.binread(@cache_file)) rescue StandardError # Fallback: reparse if cache corrupted or any error parse_and_cache end |