Class: Dotsync::ConfigCache
- Inherits:
-
Object
- Object
- Dotsync::ConfigCache
- Includes:
- XDGBaseDirectory
- Defined in:
- lib/dotsync/utils/config_cache.rb
Instance Method Summary collapse
-
#initialize(config_path) ⇒ ConfigCache
constructor
A new instance of ConfigCache.
- #load ⇒ Object
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.
10 11 12 13 14 15 16 17 18 |
# File 'lib/dotsync/utils/config_cache.rb', line 10 def initialize(config_path) @config_path = File.(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
#load ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/dotsync/utils/config_cache.rb', line 20 def load # Skip cache if disabled via environment variable return parse_toml if ENV["DOTSYNC_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 |