Class: KeeperSecretsManager::Cache

Inherits:
Object
  • Object
show all
Defined in:
lib/keeper_secrets_manager/cache.rb

Overview

File-based caching for disaster recovery Stores encrypted API responses to allow offline access when network is unavailable

Class Method Summary collapse

Class Method Details

.cache_exists?Boolean

Check if cache file exists

Returns:

  • (Boolean)


42
43
44
# File 'lib/keeper_secrets_manager/cache.rb', line 42

def self.cache_exists?
  File.exist?(cache_file_path)
end

.cache_file_pathObject

Default cache file location - can be overridden with KSM_CACHE_DIR environment variable



8
9
10
11
# File 'lib/keeper_secrets_manager/cache.rb', line 8

def self.cache_file_path
  cache_dir = ENV['KSM_CACHE_DIR'] || '.'
  File.join(cache_dir, 'ksm_cache.bin')
end

.clear_cacheObject

Remove cache file



35
36
37
38
39
# File 'lib/keeper_secrets_manager/cache.rb', line 35

def self.clear_cache
  File.delete(cache_file_path) if File.exist?(cache_file_path)
rescue StandardError => e
  warn "Failed to delete cache: #{e.message}" if ENV['KSM_DEBUG']
end

.get_cached_dataObject

Load encrypted cache data



24
25
26
27
28
29
30
31
32
# File 'lib/keeper_secrets_manager/cache.rb', line 24

def self.get_cached_data
  return nil unless File.exist?(cache_file_path)

  File.open(cache_file_path, 'rb', &:read)
rescue StandardError => e
  # Silently fail on cache read errors
  warn "Failed to read cache: #{e.message}" if ENV['KSM_DEBUG']
  nil
end

.save_cache(data) ⇒ Object

Save encrypted cache data (transmission key + encrypted response)



14
15
16
17
18
19
20
21
# File 'lib/keeper_secrets_manager/cache.rb', line 14

def self.save_cache(data)
  File.open(cache_file_path, 'wb') do |file|
    file.write(data)
  end
rescue StandardError => e
  # Silently fail on cache write errors (don't break the app)
  warn "Failed to write cache: #{e.message}" if ENV['KSM_DEBUG']
end