Sepia::InMemoryStorage
Inherits Sepia::StorageBackend < Reference < Object
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
Instance methods
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
Import data from a hash structure
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