How krishnazawar/swiftcache works
SwiftCache is a single-threaded, in-memory key-value database exposed through a TCP command interface. A client command is received by the server, parsed and dispatched to a type-specific or generic driver, which operates on the database and returns a response. The database stores typed values, manages key expiry and incremental rehashing, and can optionally recover from and append to a write-ahead log. Source excerpts are partial, so links for unsampled drivers and database internals reflect documented capabilities and visible interfaces; uncertain implementation details are omitted.
Main entry points: main.cpp Server loop · parser.cpp Command parser · database.cpp Key database · wal.cpp WAL manager
Components 16
TCP interface
- Server loop
src/main.cpp - Socket platform
src/platform/socket.cpp
Command handling
- Command parser
src/parser.cpp - String driver
src/drivers/stringDriver.cpp - List driver
src/drivers/listDriver.cpp - Hash driver
src/drivers/hashDriver.cpp - Generic driver
src/drivers/genericsDriver.cpp
Database storage
- Key database
src/database/database.cpp - Expiry and rehash
src/database/database.cpp
Value types
- Key object
src/models/object.cpp - Typed value
src/models/value.cpp - List datatype
src/models/datatypes/listDatatype.cpp - Hash datatype
src/models/datatypes/hashDatatype.cpp
Persistence
- WAL manager
src/WAL/wal.cpp
Other components
- TCP client
- WAL file
Connections 23
- TCP client → Server loop: sends commands
- Server loop → Socket platform: initializes sockets
- Server loop → Command parser: parses commands
- Server loop → TCP client: sends responses
- Command parser → String driver: dispatches strings
- Command parser → List driver: dispatches lists
- Command parser → Hash driver: dispatches hashes
- Command parser → Generic driver: dispatches generic
- String driver → Key database: reads and writes
- List driver → Key database: reads and writes
- Hash driver → Key database: reads and writes
- Generic driver → Key database: reads and writes
- Key database → Key object: stores objects
- Key database → Expiry and rehash: runs maintenance
- Key object → Typed value: holds value
- Typed value → List datatype: wraps lists
- Typed value → Hash datatype: wraps hashes
- Server loop → WAL manager: configures optional WAL
- Server loop → Command parser: replays log commands
- Command parser → WAL manager: appends commands
- Key database → WAL manager: coordinates compaction
- WAL manager → WAL file: dumps and compacts
- Server loop → WAL file: loads on startup