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
28 29 30 31 32 33 34 |
# File 'lib/mudis/persistence.rb', line 28 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
17 18 19 20 21 22 23 24 25 |
# File 'lib/mudis/persistence.rb', line 17 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
7 8 9 10 11 12 13 14 |
# File 'lib/mudis/persistence.rb', line 7 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 |