Module: Mudis::Persistence
- Included in:
- Mudis
- Defined in:
- lib/mudis/persistence.rb
Overview
Persistence module handles snapshot save/load operations for warm boot support
Instance Method Summary collapse
-
#install_persistence_hook! ⇒ Object
Installs an at_exit hook to save the snapshot on process exit.
-
#load_snapshot! ⇒ Object
Loads the cache state from disk for persistence.
-
#save_snapshot! ⇒ Object
Saves the current cache state to disk for persistence.
Instance Method Details
#install_persistence_hook! ⇒ Object
Installs an at_exit hook to save the snapshot on process exit
30 31 32 33 34 35 36 |
# File 'lib/mudis/persistence.rb', line 30 def install_persistence_hook! return unless @persistence_enabled return if defined?(@persistence_hook_installed) && @persistence_hook_installed at_exit { save_snapshot! } @persistence_hook_installed = true end |
#load_snapshot! ⇒ Object
Loads the cache state from disk for persistence
19 20 21 22 23 24 25 26 27 |
# File 'lib/mudis/persistence.rb', line 19 def load_snapshot! return unless @persistence_enabled return unless File.exist?(@persistence_path) data = read_snapshot snapshot_restore(data) rescue StandardError => e warn "[Mudis] Failed to load snapshot: #{e.class}: #{e.message}" end |
#save_snapshot! ⇒ Object
Saves the current cache state to disk for persistence
9 10 11 12 13 14 15 16 |
# File 'lib/mudis/persistence.rb', line 9 def save_snapshot! return unless @persistence_enabled data = snapshot_dump safe_write_snapshot(data) rescue StandardError => e warn "[Mudis] Failed to save snapshot: #{e.class}: #{e.message}" end |