Class: Dotsync::ConfigCache

Inherits:
Object
  • Object
show all
Includes:
PathUtils, XDGBaseDirectory
Defined in:
lib/dotsync/utils/config_cache.rb

Constant Summary

Constants included from PathUtils

PathUtils::ENV_VARS_COLOR

Instance Method Summary collapse

Methods included from PathUtils

#colorize_env_vars, #expand_env_vars, #extract_env_vars, #path_is_parent_or_same?, #relative_to_absolute, #sanitize_path, #translate_tmp_path

Methods included from XDGBaseDirectory

#xdg_bin_home, #xdg_cache_home, #xdg_config_home, #xdg_data_home

Constructor Details

#initialize(config_path) ⇒ ConfigCache

Returns a new instance of ConfigCache.



12
13
14
15
16
17
18
19
20
# File 'lib/dotsync/utils/config_cache.rb', line 12

def initialize(config_path)
  @config_path = File.expand_path(config_path)
  @cache_dir = File.join(xdg_data_home, "dotsync", "config_cache")

  # Use hash of real path for cache filename to support multiple configs
  cache_key = Digest::SHA256.hexdigest(File.realpath(@config_path))
  @cache_file = File.join(@cache_dir, "#{cache_key}.cache")
  @meta_file = File.join(@cache_dir, "#{cache_key}.meta")
end

Instance Method Details

#loadObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/dotsync/utils/config_cache.rb', line 22

def load
  # Skip cache if disabled via environment variable
  return resolve_config if ENV["DOTSYNC_NO_CACHE"]

  return parse_and_cache unless valid_cache?

  # Fast path: load from cache
  Marshal.load(File.binread(@cache_file))
rescue ConfigError
  raise
rescue StandardError
  # Fallback: reparse if cache corrupted or any error
  parse_and_cache
end