class
Sepia::InMemoryStorage
- Sepia::InMemoryStorage
- Sepia::StorageBackend
- Reference
- Object
Overview
In-memory storage backend for Sepia objects.
This backend stores all data in memory hashes without any filesystem operations. It's primarily useful for:
- Testing: Fast operations without disk I/O
- Demos: Self-contained examples that don't persist data
- Temporary data: Caching or session storage
Data Structure
The storage uses three main hashes:
@serializable_storage: Maps class_name/id to serialized content@container_storage: Maps class_name/id to property data and references@container_references: Maps container paths to reference mappings
Example
# Configure Sepia to use in-memory storage
Sepia::Storage.configure(:memory)
# Objects will be stored in memory only
doc = MyDocument.new("Hello")
doc.save # Stored in @serializable_storage
Defined in:
sepia/in_memory_storage.crInstance Method Summary
-
#clear
Clears all data from memory storage.
-
#count(object_class : Class) : Int32
Count objects of a given class
-
#delete(class_name : String, id : String)
Delete an object by its class name and ID
-
#delete(object : Serializable | Container)
Delete an object
-
#exists?(object_class : Class, id : String) : Bool
Check if an object exists
-
#export_data : Hash(String, Array(Hash(String, String)))
Export all data as a hash structure
- #get_container_references(container_path : String) : Hash(String, String)
- #get_reference(container_path : String, ref_name : String) : String | Nil
-
#import_data(data : Hash(String, Array(Hash(String, String))))
Import data from a hash structure
-
#list_all(object_class : Class) : Array(String)
List all object IDs of a given class
-
#list_all_objects : Hash(String, Array(String))
List all objects, grouped by class name
-
#load(object_class : Class, id : String, path : String | Nil = nil) : Object
Loads an object from memory storage.
-
#save(object : Container, path : String | Nil = nil)
Saves a Container object to memory storage.
-
#save(object : Serializable, path : String | Nil = nil)
Saves a Serializable object to memory storage.
- #store_container_reference(container_path : String, ref_name : String, target_container : Container)
-
#store_reference(container_path : String, ref_name : String, target_class : String, target_id : String)
Methods to support container references (for internal use by Container module)
Instance methods inherited from class Sepia::StorageBackend
clear
clear,
count(object_class : Class) : Int32
count,
delete(class_name : String, id : String)delete(object : Serializable | Container) delete, exists?(object_class : Class, id : String) : Bool exists?, export_data : Hash(String, Array(Hash(String, String))) export_data, import_data(data : Hash(String, Array(Hash(String, String)))) import_data, list_all(object_class : Class) : Array(String) list_all, list_all_objects : Hash(String, Array(String)) list_all_objects, load(object_class : Class, id : String, path : String | Nil = nil) : Object load, save(object : Serializable, path : String | Nil = nil)
save(object : Container, path : String | Nil = nil) save
Instance Method Detail
Clears all data from memory storage.
Empties all internal hashes, effectively resetting the storage to its initial empty state.
storage.clear # All data is now gone
Count objects of a given class
Delete an object by its class name and ID
Delete an object
Check if an object exists
Export all data as a hash structure
Import data from a hash structure
List all object IDs of a given class
List all objects, grouped by class name
Loads an object from memory storage.
Retrieves and deserializes an object of the specified class.
For Serializable objects, uses the class's from_sepia method.
For Container objects, restores primitive properties from JSON and
loads references if a path is provided.
Raises an exception if the object is not found.
# Load a Serializable object
doc = storage.load(MyDocument, "doc-uuid")
# Load a Container object
board = storage.load(MyBoard, "board-uuid")
Saves a Container object to memory storage.
Stores the container's metadata and primitive properties in the
@container_storage hash. Primitive properties are serialized to JSON
and stored under the "_data" key.
board = Board.new("My Board")
storage = InMemoryStorage.new
storage.save(board) # Stored in @container_storage
Saves a Serializable object to memory storage.
Stores the object's serialized content in the @serializable_storage hash.
The key is the full path (including the base path) to maintain
compatibility with FileStorage.
doc = MyDocument.new("Hello")
storage = InMemoryStorage.new
storage.save(doc) # Stored in @serializable_storage
Methods to support container references (for internal use by Container module)